1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
---|
2 | * JFlex 1.4.3 *
|
---|
3 | * Copyright (C) 1998-2009 Gerwin Klein <[email protected]> *
|
---|
4 | * All rights reserved. *
|
---|
5 | * *
|
---|
6 | * This program is free software; you can redistribute it and/or modify *
|
---|
7 | * it under the terms of the GNU General Public License. See the file *
|
---|
8 | * COPYRIGHT for more information. *
|
---|
9 | * *
|
---|
10 | * This program is distributed in the hope that it will be useful, *
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
---|
13 | * GNU General Public License for more details. *
|
---|
14 | * *
|
---|
15 | * You should have received a copy of the GNU General Public License along *
|
---|
16 | * with this program; if not, write to the Free Software Foundation, Inc., *
|
---|
17 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
---|
18 | * *
|
---|
19 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
---|
20 |
|
---|
21 | package JFlex;
|
---|
22 |
|
---|
23 | import java.util.*;
|
---|
24 |
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Simple symbol table, mapping lexical state names to integers.
|
---|
28 | *
|
---|
29 | * @author Gerwin Klein
|
---|
30 | * @version JFlex 1.4.3, $Revision: 433 $, $Date: 2009-01-31 19:52:34 +1100 (Sat, 31 Jan 2009) $
|
---|
31 | */
|
---|
32 | public class LexicalStates {
|
---|
33 |
|
---|
34 | /** maps state name to state number */
|
---|
35 | Hashtable states;
|
---|
36 |
|
---|
37 | /** codes of inclusive states (subset of states) */
|
---|
38 | Vector inclusive;
|
---|
39 |
|
---|
40 | /** number of declared states */
|
---|
41 | int numStates;
|
---|
42 |
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * constructs a new lexical state symbol table
|
---|
46 | */
|
---|
47 | public LexicalStates() {
|
---|
48 | states = new Hashtable();
|
---|
49 | inclusive = new Vector();
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * insert a new state declaration
|
---|
55 | */
|
---|
56 | public void insert(String name, boolean is_inclusive) {
|
---|
57 | if ( states.containsKey(name) ) return;
|
---|
58 |
|
---|
59 | Integer code = new Integer(numStates++);
|
---|
60 | states.put(name, code);
|
---|
61 |
|
---|
62 | if (is_inclusive)
|
---|
63 | inclusive.addElement(code);
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * returns the number (code) of a declared state,
|
---|
69 | * <code>null</code> if no such state has been declared.
|
---|
70 | */
|
---|
71 | public Integer getNumber(String name) {
|
---|
72 | return (Integer) states.get(name);
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * returns the number of declared states
|
---|
78 | */
|
---|
79 | public int number() {
|
---|
80 | return numStates;
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * returns the names of all states
|
---|
86 | */
|
---|
87 | public Enumeration names() {
|
---|
88 | return states.keys();
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * returns the code of all inclusive states
|
---|
93 | */
|
---|
94 | public Enumeration getInclusiveStates() {
|
---|
95 | return inclusive.elements();
|
---|
96 | }
|
---|
97 | }
|
---|