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
import java.util.Enumeration;
37
/** This class represents the complete "action" table of the parser.
38
* It has one row for each state in the parse machine, and a column for
39
* each terminal symbol. Each entry in the table represents a shift,
40
* reduce, or an error.
42
* @see weka.core.parser.java_cup.parse_action
43
* @see weka.core.parser.java_cup.parse_action_row
44
* @version last updated: 11/25/95
45
* @author Scott Hudson
47
public class parse_action_table {
49
/*-----------------------------------------------------------*/
50
/*--- Constructor(s) ----------------------------------------*/
51
/*-----------------------------------------------------------*/
53
/** Simple constructor. All terminals, non-terminals, and productions must
54
* already have been entered, and the viable prefix recognizer should
55
* have been constructed before this is called.
57
public parse_action_table()
59
/* determine how many states we are working with */
60
_num_states = lalr_state.number();
62
/* allocate the array and fill it in with empty rows */
63
under_state = new parse_action_row[_num_states];
64
for (int i=0; i<_num_states; i++)
65
under_state[i] = new parse_action_row();
68
/*-----------------------------------------------------------*/
69
/*--- (Access to) Instance Variables ------------------------*/
70
/*-----------------------------------------------------------*/
72
/** How many rows/states are in the machine/table. */
73
protected int _num_states;
75
/** How many rows/states are in the machine/table. */
76
public int num_states() {return _num_states;}
78
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
80
/** Actual array of rows, one per state. */
81
public parse_action_row[] under_state;
83
/*-----------------------------------------------------------*/
84
/*--- General Methods ---------------------------------------*/
85
/*-----------------------------------------------------------*/
87
/** Check the table to ensure that all productions have been reduced.
88
* Issue a warning message (to System.err) for each production that
91
public void check_reductions()
97
/* tabulate reductions -- look at every table entry */
98
for (int row = 0; row < num_states(); row++)
100
for (int col = 0; col < parse_action_row.size(); col++)
102
/* look at the action entry to see if its a reduce */
103
act = under_state[row].under_term[col];
104
if (act != null && act.kind() == parse_action.REDUCE)
106
/* tell production that we used it */
107
((reduce_action)act).reduce_with().note_reduction_use();
112
/* now go across every production and make sure we hit it */
113
for (Enumeration p = production.all(); p.hasMoreElements(); )
115
prod = (production)p.nextElement();
117
/* if we didn't hit it give a warning */
118
if (prod.num_reductions() == 0)
123
/* give a warning if they haven't been turned off */
127
ErrorManager.getManager().emit_warning("*** Production \"" +
128
prod.to_simple_string() + "\" never reduced");
134
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*
136
/** Convert to a string. */
137
public String toString()
142
result = "-------- ACTION_TABLE --------\n";
143
for (int row = 0; row < num_states(); row++)
145
result += "From state #" + row + "\n";
147
for (int col = 0; col < parse_action_row.size(); col++)
149
/* if the action is not an error print it */
150
if (under_state[row].under_term[col].kind() != parse_action.ERROR)
152
result += " [term " + col + ":" + under_state[row].under_term[col] + "]";
154
/* end the line after the 2nd one */
163
/* finish the line if we haven't just done that */
164
if (cnt != 0) result += "\n";
166
result += "------------------------------";
171
/*-----------------------------------------------------------*/