Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/com/sun/java_cup/internal/runtime/Symbol.java
38829 views
/*1* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.java_cup.internal.runtime;2627/**28* Defines the Symbol class, which is used to represent all terminals29* and nonterminals while parsing. The lexer should pass CUP Symbols30* and CUP returns a Symbol.31*32* @author Frank Flannery33*/3435/* ****************************************************************36Class Symbol37what the parser expects to receive from the lexer.38the token is identified as follows:39sym: the symbol type40parse_state: the parse state.41value: is the lexical value of type Object42left : is the left position in the original input file43right: is the right position in the original input file44******************************************************************/4546public class Symbol {4748/*******************************49Constructor for l,r values50*******************************/5152public Symbol(int id, int l, int r, Object o) {53this(id);54left = l;55right = r;56value = o;57}5859/*******************************60Constructor for no l,r values61********************************/6263public Symbol(int id, Object o) {64this(id);65left = -1;66right = -1;67value = o;68}6970/*****************************71Constructor for no value72***************************/7374public Symbol(int sym_num, int l, int r) {75sym = sym_num;76left = l;77right = r;78value = null;79}8081/***********************************82Constructor for no value or l,r83***********************************/8485public Symbol(int sym_num) {86this(sym_num, -1);87left = -1;88right = -1;89value = null;90}9192/***********************************93Constructor to give a start state94***********************************/95public Symbol(int sym_num, int state)96{97sym = sym_num;98parse_state = state;99}100101/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/102103/** The symbol number of the terminal or non terminal being represented */104public int sym;105106/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/107108/** The parse state to be recorded on the parse stack with this symbol.109* This field is for the convenience of the parser and shouldn't be110* modified except by the parser.111*/112public int parse_state;113/** This allows us to catch some errors caused by scanners recycling114* symbols. For the use of the parser only. [CSA, 23-Jul-1999] */115boolean used_by_parser = false;116117/*******************************118The data passed to parser119*******************************/120121public int left, right;122public Object value;123124/*****************************125Printing this token out. (Override for pretty-print).126****************************/127public String toString() { return "#"+sym; }128}129130131