001: /*
002: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.java_cup.internal.runtime;
027:
028: /**
029: * Defines the Symbol class, which is used to represent all terminals
030: * and nonterminals while parsing. The lexer should pass CUP Symbols
031: * and CUP returns a Symbol.
032: *
033: * @version last updated: 7/3/96
034: * @author Frank Flannery
035: */
036:
037: /* ****************************************************************
038: Class Symbol
039: what the parser expects to receive from the lexer.
040: the token is identified as follows:
041: sym: the symbol type
042: parse_state: the parse state.
043: value: is the lexical value of type Object
044: left : is the left position in the original input file
045: right: is the right position in the original input file
046: ******************************************************************/
047:
048: public class Symbol {
049:
050: /*******************************
051: Constructor for l,r values
052: *******************************/
053:
054: public Symbol(int id, int l, int r, Object o) {
055: this (id);
056: left = l;
057: right = r;
058: value = o;
059: }
060:
061: /*******************************
062: Constructor for no l,r values
063: ********************************/
064:
065: public Symbol(int id, Object o) {
066: this (id);
067: left = -1;
068: right = -1;
069: value = o;
070: }
071:
072: /*****************************
073: Constructor for no value
074: ***************************/
075:
076: public Symbol(int sym_num, int l, int r) {
077: sym = sym_num;
078: left = l;
079: right = r;
080: value = null;
081: }
082:
083: /***********************************
084: Constructor for no value or l,r
085: ***********************************/
086:
087: public Symbol(int sym_num) {
088: this (sym_num, -1);
089: left = -1;
090: right = -1;
091: value = null;
092: }
093:
094: /***********************************
095: Constructor to give a start state
096: ***********************************/
097: public Symbol(int sym_num, int state) {
098: sym = sym_num;
099: parse_state = state;
100: }
101:
102: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
103:
104: /** The symbol number of the terminal or non terminal being represented */
105: public int sym;
106:
107: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
108:
109: /** The parse state to be recorded on the parse stack with this symbol.
110: * This field is for the convenience of the parser and shouldn't be
111: * modified except by the parser.
112: */
113: public int parse_state;
114: /** This allows us to catch some errors caused by scanners recycling
115: * symbols. For the use of the parser only. [CSA, 23-Jul-1999] */
116: boolean used_by_parser = false;
117:
118: /*******************************
119: The data passed to parser
120: *******************************/
121:
122: public int left, right;
123: public Object value;
124:
125: /*****************************
126: Printing this token out. (Override for pretty-print).
127: ****************************/
128: public String toString() {
129: return "#" + sym;
130: }
131: }
|