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