KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java_cup > internal > runtime > Symbol


1 package com.sun.java_cup.internal.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 ******************************************************************/

22
23 public class Symbol {
24
25 /*******************************
26   Constructor for l,r values
27  *******************************/

28
29   public Symbol(int id, int l, int r, Object JavaDoc o) {
30     this(id);
31     left = l;
32     right = r;
33     value = o;
34   }
35
36 /*******************************
37   Constructor for no l,r values
38 ********************************/

39
40   public Symbol(int id, Object JavaDoc o) {
41     this(id);
42     left = -1;
43     right = -1;
44     value = o;
45   }
46
47 /*****************************
48   Constructor for no value
49   ***************************/

50
51   public Symbol(int sym_num, int l, int r) {
52     sym = sym_num;
53     left = l;
54     right = r;
55     value = null;
56   }
57
58 /***********************************
59   Constructor for no value or l,r
60 ***********************************/

61
62   public Symbol(int sym_num) {
63     this(sym_num, -1);
64     left = -1;
65     right = -1;
66     value = null;
67   }
68
69 /***********************************
70   Constructor to give a start state
71 ***********************************/

72   public Symbol(int sym_num, int state)
73     {
74       sym = sym_num;
75       parse_state = state;
76     }
77
78 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
79
80   /** The symbol number of the terminal or non terminal being represented */
81   public int sym;
82
83   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
84
85   /** The parse state to be recorded on the parse stack with this symbol.
86    * This field is for the convenience of the parser and shouldn't be
87    * modified except by the parser.
88    */

89   public int parse_state;
90   /** This allows us to catch some errors caused by scanners recycling
91    * symbols. For the use of the parser only. [CSA, 23-Jul-1999] */

92   boolean used_by_parser = false;
93
94 /*******************************
95   The data passed to parser
96  *******************************/

97
98   public int left, right;
99   public Object JavaDoc value;
100
101   /*****************************
102     Printing this token out. (Override for pretty-print).
103     ****************************/

104   public String JavaDoc toString() { return "#"+sym; }
105 }
106
107
108
109
110
111
112
Popular Tags