2
* STANDARD ML OF NEW JERSEY COPYRIGHT NOTICE, LICENSE AND DISCLAIMER.
4
* Copyright (c) 1989-1998 by Lucent Technologies
6
* Permission to use, copy, modify, and distribute this software and its
7
* documentation for any purpose and without fee is hereby granted, provided
8
* that the above copyright notice appear in all copies and that both the
9
* copyright notice and this permission notice and warranty disclaimer appear
10
* in supporting documentation, and that the name of Lucent Technologies, Bell
11
* Labs or any Lucent entity not be used in advertising or publicity pertaining
12
* to distribution of the software without specific, written prior permission.
14
* Lucent disclaims all warranties with regard to this software, including all
15
* implied warranties of merchantability and fitness. In no event shall Lucent
16
* be liable for any special, indirect or consequential damages or any damages
17
* whatsoever resulting from loss of use, data or profits, whether in an action
18
* of contract, negligence or other tortious action, arising out of or in
19
* connection with the use or performance of this software.
21
* Taken from this URL:
22
* http://www.smlnj.org/license.html
24
* This license is compatible with the GNU GPL (see section "Standard ML of New
25
* Jersey Copyright License"):
26
* http://www.gnu.org/licenses/license-list.html#StandardMLofNJ
30
* Copyright 1996-1999 by Scott Hudson, Frank Flannery, C. Scott Ananian
33
package weka.core.parser.java_cup;
35
/** This abstract class serves as the base class for grammar symbols (i.e.,
36
* both terminals and non-terminals). Each symbol has a name string, and
37
* a string giving the type of object that the symbol will be represented by
38
* on the runtime parse stack. In addition, each symbol maintains a use count
39
* in order to detect symbols that are declared but never used, and an index
40
* number that indicates where it appears in parse tables (index numbers are
41
* unique within terminals or non terminals, but not across both).
43
* @see weka.core.parser.java_cup.terminal
44
* @see weka.core.parser.java_cup.non_terminal
45
* @version last updated: 7/3/96
46
* @author Frank Flannery
48
public abstract class symbol {
49
/*-----------------------------------------------------------*/
50
/*--- Constructor(s) ----------------------------------------*/
51
/*-----------------------------------------------------------*/
54
* @param nm the name of the symbol.
55
* @param tp a string with the type name.
57
public symbol(String nm, String tp)
60
if (nm == null) nm = "";
62
/* apply default if no type given */
63
if (tp == null) tp = "Object";
69
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
71
/** Constructor with default type.
72
* @param nm the name of the symbol.
74
public symbol(String nm)
79
/*-----------------------------------------------------------*/
80
/*--- (Access to) Instance Variables ------------------------*/
81
/*-----------------------------------------------------------*/
83
/** String for the human readable name of the symbol. */
84
protected String _name;
86
/** String for the human readable name of the symbol. */
87
public String name() {return _name;}
89
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
91
/** String for the type of object used for the symbol on the parse stack. */
92
protected String _stack_type;
94
/** String for the type of object used for the symbol on the parse stack. */
95
public String stack_type() {return _stack_type;}
97
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
99
/** Count of how many times the symbol appears in productions. */
100
protected int _use_count = 0;
102
/** Count of how many times the symbol appears in productions. */
103
public int use_count() {return _use_count;}
105
/** Increment the use count. */
106
public void note_use() {_use_count++;}
108
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
110
/** Index of this symbol (terminal or non terminal) in the parse tables.
111
* Note: indexes are unique among terminals and unique among non terminals,
112
* however, a terminal may have the same index as a non-terminal, etc.
114
protected int _index;
116
/** Index of this symbol (terminal or non terminal) in the parse tables.
117
* Note: indexes are unique among terminals and unique among non terminals,
118
* however, a terminal may have the same index as a non-terminal, etc.
120
public int index() {return _index;}
122
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
124
/** Indicate if this is a non-terminal. Here in the base class we
125
* don't know, so this is abstract.
127
public abstract boolean is_non_term();
129
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
131
/** Convert to a string. */
132
public String toString()
137
/*-----------------------------------------------------------*/