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: ******************************************************************/
022:
023: public class Symbol {
024:
025: /*******************************
026: Constructor for l,r values
027: *******************************/
028:
029: public Symbol(int id, int l, int r, Object o) {
030: this (id);
031: left = l;
032: right = r;
033: value = o;
034: }
035:
036: /*******************************
037: Constructor for no l,r values
038: ********************************/
039:
040: public Symbol(int id, Object o) {
041: this (id);
042: left = -1;
043: right = -1;
044: value = o;
045: }
046:
047: /*****************************
048: Constructor for no value
049: ***************************/
050:
051: public Symbol(int sym_num, int l, int r) {
052: sym = sym_num;
053: left = l;
054: right = r;
055: value = null;
056: }
057:
058: /***********************************
059: Constructor for no value or l,r
060: ***********************************/
061:
062: public Symbol(int sym_num) {
063: this (sym_num, -1);
064: left = -1;
065: right = -1;
066: value = null;
067: }
068:
069: /***********************************
070: Constructor to give a start state
071: ***********************************/
072: public Symbol(int sym_num, int state) {
073: sym = sym_num;
074: parse_state = state;
075: }
076:
077: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
078:
079: /** The symbol number of the terminal or non terminal being represented */
080: public int sym;
081:
082: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
083:
084: /** The parse state to be recorded on the parse stack with this symbol.
085: * This field is for the convenience of the parser and shouldn't be
086: * modified except by the parser.
087: */
088: public int parse_state;
089: /** This allows us to catch some errors caused by scanners recycling
090: * symbols. For the use of the parser only. [CSA, 23-Jul-1999] */
091: boolean used_by_parser = false;
092:
093: /*******************************
094: The data passed to parser
095: *******************************/
096:
097: public int left, right;
098: public Object value;
099:
100: /*****************************
101: Printing this token out. (Override for pretty-print).
102: ****************************/
103: public String toString() {
104: return "#" + sym;
105: }
106: }
|