1 | package java_cup.runtime;
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * Defines the Symbol class, which is used to represent all terminals
|
---|
5 | * and nonterminals while parsing. The lexer should pass CUP Symbols
|
---|
6 | * and CUP returns a Symbol.
|
---|
7 | *
|
---|
8 | * @version last updated: 7/3/96
|
---|
9 | * @author Frank Flannery
|
---|
10 | */
|
---|
11 |
|
---|
12 | /* ****************************************************************
|
---|
13 | Class Symbol
|
---|
14 | what the parser expects to receive from the lexer.
|
---|
15 | the token is identified as follows:
|
---|
16 | sym: the symbol type
|
---|
17 | parse_state: the parse state.
|
---|
18 | value: is the lexical value of type Object
|
---|
19 | left : is the left position in the original input file
|
---|
20 | right: is the right position in the original input file
|
---|
21 | xleft: is the left position Object in the original input file
|
---|
22 | xright: is the left position Object in the original input file
|
---|
23 | ******************************************************************/
|
---|
24 |
|
---|
25 | public class Symbol {
|
---|
26 |
|
---|
27 | // TUM 20060327: Added new Constructor to provide more flexible way
|
---|
28 | // for location handling
|
---|
29 | /*******************************
|
---|
30 | *******************************/
|
---|
31 | public Symbol(int id, Symbol left, Symbol right, Object o){
|
---|
32 | this(id,left.left,right.right,o);
|
---|
33 | }
|
---|
34 | public Symbol(int id, Symbol left, Symbol right){
|
---|
35 | this(id,left.left,right.right);
|
---|
36 | }
|
---|
37 | /*******************************
|
---|
38 | Constructor for l,r values
|
---|
39 | *******************************/
|
---|
40 |
|
---|
41 | public Symbol(int id, int l, int r, Object o) {
|
---|
42 | this(id);
|
---|
43 | left = l;
|
---|
44 | right = r;
|
---|
45 | value = o;
|
---|
46 | }
|
---|
47 |
|
---|
48 | /*******************************
|
---|
49 | Constructor for no l,r values
|
---|
50 | ********************************/
|
---|
51 |
|
---|
52 | public Symbol(int id, Object o) {
|
---|
53 | this(id, -1, -1, o);
|
---|
54 | }
|
---|
55 |
|
---|
56 | /*****************************
|
---|
57 | Constructor for no value
|
---|
58 | ***************************/
|
---|
59 |
|
---|
60 | public Symbol(int id, int l, int r) {
|
---|
61 | this(id, l, r, null);
|
---|
62 | }
|
---|
63 |
|
---|
64 | /***********************************
|
---|
65 | Constructor for no value or l,r
|
---|
66 | ***********************************/
|
---|
67 |
|
---|
68 | public Symbol(int sym_num) {
|
---|
69 | this(sym_num, -1);
|
---|
70 | left = -1;
|
---|
71 | right = -1;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /***********************************
|
---|
75 | Constructor to give a start state
|
---|
76 | ***********************************/
|
---|
77 | Symbol(int sym_num, int state)
|
---|
78 | {
|
---|
79 | sym = sym_num;
|
---|
80 | parse_state = state;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
|
---|
84 |
|
---|
85 | /** The symbol number of the terminal or non terminal being represented */
|
---|
86 | public int sym;
|
---|
87 |
|
---|
88 | /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
|
---|
89 |
|
---|
90 | /** The parse state to be recorded on the parse stack with this symbol.
|
---|
91 | * This field is for the convenience of the parser and shouldn't be
|
---|
92 | * modified except by the parser.
|
---|
93 | */
|
---|
94 | public int parse_state;
|
---|
95 | /** This allows us to catch some errors caused by scanners recycling
|
---|
96 | * symbols. For the use of the parser only. [CSA, 23-Jul-1999] */
|
---|
97 | boolean used_by_parser = false;
|
---|
98 |
|
---|
99 | /*******************************
|
---|
100 | The data passed to parser
|
---|
101 | *******************************/
|
---|
102 |
|
---|
103 | public int left, right;
|
---|
104 | public Object value;
|
---|
105 |
|
---|
106 | /*****************************
|
---|
107 | Printing this token out. (Override for pretty-print).
|
---|
108 | ****************************/
|
---|
109 | public String toString() { return "#"+sym; }
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 |
|
---|
116 |
|
---|