001: package java_cup.runtime;
002:
003: /**
004: * Defines the Symbol class, which is used to represent all terminals
005: * and nonterminals while parsing. The lexer should pass CUP Symbols
006: * and CUP returns a Symbol.
007: *
008: * @version last updated: 7/3/96
009: * @author Frank Flannery
010: */
011:
012: /* ****************************************************************
013: Class Symbol
014: what the parser expects to receive from the lexer.
015: the token is identified as follows:
016: sym: the symbol type
017: parse_state: the parse state.
018: value: is the lexical value of type Object
019: left : is the left position in the original input file
020: right: is the right position in the original input file
021: xleft: is the left position Object in the original input file
022: xright: is the left position Object in the original input file
023: ******************************************************************/
024:
025: public class Symbol {
026:
027: // TUM 20060327: Added new Constructor to provide more flexible way
028: // for location handling
029: /*******************************
030: *******************************/
031: public Symbol(int id, Symbol left, Symbol right, Object o) {
032: this (id, left.left, right.right, o);
033: }
034:
035: public Symbol(int id, Symbol left, Symbol right) {
036: this (id, left.left, right.right);
037: }
038:
039: /*******************************
040: Constructor for l,r values
041: *******************************/
042:
043: public Symbol(int id, int l, int r, Object o) {
044: this (id);
045: left = l;
046: right = r;
047: value = o;
048: }
049:
050: /*******************************
051: Constructor for no l,r values
052: ********************************/
053:
054: public Symbol(int id, Object o) {
055: this (id, -1, -1, o);
056: }
057:
058: /*****************************
059: Constructor for no value
060: ***************************/
061:
062: public Symbol(int id, int l, int r) {
063: this (id, l, r, null);
064: }
065:
066: /***********************************
067: Constructor for no value or l,r
068: ***********************************/
069:
070: public Symbol(int sym_num) {
071: this (sym_num, -1);
072: left = -1;
073: right = -1;
074: }
075:
076: /***********************************
077: Constructor to give a start state
078: ***********************************/
079: Symbol(int sym_num, int state) {
080: sym = sym_num;
081: parse_state = state;
082: }
083:
084: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
085:
086: /** The symbol number of the terminal or non terminal being represented */
087: public int sym;
088:
089: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
090:
091: /** The parse state to be recorded on the parse stack with this symbol.
092: * This field is for the convenience of the parser and shouldn't be
093: * modified except by the parser.
094: */
095: public int parse_state;
096: /** This allows us to catch some errors caused by scanners recycling
097: * symbols. For the use of the parser only. [CSA, 23-Jul-1999] */
098: boolean used_by_parser = false;
099:
100: /*******************************
101: The data passed to parser
102: *******************************/
103:
104: public int left, right;
105: public Object value;
106:
107: /*****************************
108: Printing this token out. (Override for pretty-print).
109: ****************************/
110: public String toString() {
111: return "#" + sym;
112: }
113: }
|