3 # character in column 1 determines outcome...
6 # t is copied as //t if -t is set
7 # other lines are interpreted to call jay procedures
9 .// created by jay 0.7 (c) 1998 Axel.Schreiner@informatik.uni-osnabrueck.de
11 prolog ## %{ ... %} prior to the first %%
15 tokens public static final int
17 . /** thrown for irrecoverable syntax errors and stack overflow.
19 . public static class yyException extends java.lang.Exception {
20 . public yyException (String message) {
25 . /** must be implemented by a scanner object to supply input to the parser.
27 . public interface yyInput {
28 . /** move on to next token.
29 . @return false if positioned beyond tokens.
30 . @throws IOException on input error.
32 . boolean advance () throws java.io.IOException;
33 . /** classifies current token.
34 . Should not be called if advance() returned false.
35 . @return current %token or single character.
38 . /** associated with current token.
39 . Should not be called if advance() returned false.
40 . @return value for token().
45 . /** simplified error message.
46 . @see <a href="#yyerror(java.lang.String, java.lang.String[])">yyerror</a>
48 . public void yyerror (String message) {
49 . yyerror(message, null);
52 . /** (syntax) error message.
53 . Can be overwritten to control message format.
54 . @param message text to be displayed.
55 . @param expected vector of acceptable tokens, if available.
57 . public void yyerror (String message, String[] expected) {
58 . if (expected != null && expected.length > 0) {
59 . System.err.print(message+", expecting");
60 . for (int n = 0; n < expected.length; ++ n)
61 . System.err.print(" "+expected[n]);
62 . System.err.println();
64 . System.err.println(message);
67 . /** debugging support, requires the package jay.yydebug.
68 . Set to null to suppress debugging messages.
70 t protected jay.yydebug.yyDebug yydebug;
72 debug ## tables for debugging support
74 . /** index-checked interface to yyNames[].
75 . @param token single character or %token value.
76 . @return token name or [illegal] or [unknown].
78 t public static final String yyname (int token) {
79 t if (token < 0 || token > yyNames.length) return "[illegal]";
81 t if ((name = yyNames[token]) != null) return name;
85 . /** computes list of expected tokens on error by tracing the tables.
86 . @param state for which to compute the list.
87 . @return list of token names.
89 . protected String[] yyExpecting (int state) {
90 . int token, n, len = 0;
91 . boolean[] ok = new boolean[yyNames.length];
93 . if ((n = yySindex[state]) != 0)
94 . for (token = n < 0 ? -n : 0;
95 . token < yyNames.length && n+token < yyTable.length; ++ token)
96 . if (yyCheck[n+token] == token && !ok[token] && yyNames[token] != null) {
100 . if ((n = yyRindex[state]) != 0)
101 . for (token = n < 0 ? -n : 0;
102 . token < yyNames.length && n+token < yyTable.length; ++ token)
103 . if (yyCheck[n+token] == token && !ok[token] && yyNames[token] != null) {
108 . String result[] = new String[len];
109 . for (n = token = 0; n < len; ++ token)
110 . if (ok[token]) result[n++] = yyNames[token];
114 . /** the generated parser, with debugging messages.
115 . Maintains a state and a value stack, currently with fixed maximum size.
116 . @param yyLex scanner.
117 . @param yydebug debug message writer implementing yyDebug, or null.
118 . @return result of the last reduction, if any.
119 . @throws yyException on irrecoverable parse error.
121 . public Object yyparse (yyInput yyLex, Object yydebug)
122 . throws java.io.IOException, yyException {
123 t this.yydebug = (jay.yydebug.yyDebug)yydebug;
124 . return yyparse(yyLex);
127 . /** initial size and increment of the state/value stack [default 256].
128 . This is not final so that it can be overwritten outside of invocations
131 . protected int yyMax;
133 . /** executed at the beginning of a reduce action.
134 . Used as $$ = yyDefault($1), prior to the user-specified action, if any.
135 . Can be overwritten to provide deep copy, etc.
136 . @param first value for $1, or null.
139 . protected Object yyDefault (Object first) {
143 . /** the generated parser.
144 . Maintains a state and a value stack, currently with fixed maximum size.
145 . @param yyLex scanner.
146 . @return result of the last reduction, if any.
147 . @throws yyException on irrecoverable parse error.
149 . public Object yyparse (yyInput yyLex)
150 . throws java.io.IOException, yyException {
151 . if (yyMax <= 0) yyMax = 256; // initial size
152 . int yyState = 0, yyStates[] = new int[yyMax]; // state stack
153 . Object yyVal = null, yyVals[] = new Object[yyMax]; // value stack
154 . int yyToken = -1; // current input
155 . int yyErrorFlag = 0; // #tks to shift
157 local ## %{ ... %} after the first %%
159 . yyLoop: for (int yyTop = 0;; ++ yyTop) {
160 . if (yyTop >= yyStates.length) { // dynamically increase
161 . int[] i = new int[yyStates.length+yyMax];
162 . System.arraycopy(yyStates, 0, i, 0, yyStates.length);
164 . Object[] o = new Object[yyVals.length+yyMax];
165 . System.arraycopy(yyVals, 0, o, 0, yyVals.length);
168 . yyStates[yyTop] = yyState;
169 . yyVals[yyTop] = yyVal;
170 t if (yydebug != null) yydebug.push(yyState, yyVal);
172 . yyDiscarded: for (;;) { // discarding a token does not change stack
174 . if ((yyN = yyDefRed[yyState]) == 0) { // else [default] reduce (yyN)
176 . yyToken = yyLex.advance() ? yyLex.token() : 0;
177 t if (yydebug != null)
178 t yydebug.lex(yyState, yyToken, yyname(yyToken), yyLex.value());
180 . if ((yyN = yySindex[yyState]) != 0 && (yyN += yyToken) >= 0
181 . && yyN < yyTable.length && yyCheck[yyN] == yyToken) {
182 t if (yydebug != null)
183 t yydebug.shift(yyState, yyTable[yyN], yyErrorFlag-1);
184 . yyState = yyTable[yyN]; // shift to yyN
185 . yyVal = yyLex.value();
187 . if (yyErrorFlag > 0) -- yyErrorFlag;
190 . if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0
191 . && yyN < yyTable.length && yyCheck[yyN] == yyToken)
192 . yyN = yyTable[yyN]; // reduce (yyN)
194 . switch (yyErrorFlag) {
197 . yyerror("syntax error", yyExpecting(yyState));
198 t if (yydebug != null) yydebug.error("syntax error");
203 . if ((yyN = yySindex[yyStates[yyTop]]) != 0
204 . && (yyN += yyErrorCode) >= 0 && yyN < yyTable.length
205 . && yyCheck[yyN] == yyErrorCode) {
206 t if (yydebug != null)
207 t yydebug.shift(yyStates[yyTop], yyTable[yyN], 3);
208 . yyState = yyTable[yyN];
209 . yyVal = yyLex.value();
212 t if (yydebug != null) yydebug.pop(yyStates[yyTop]);
213 . } while (-- yyTop >= 0);
214 t if (yydebug != null) yydebug.reject();
215 . throw new yyException("irrecoverable syntax error");
218 . if (yyToken == 0) {
219 t if (yydebug != null) yydebug.reject();
220 . throw new yyException("irrecoverable syntax error at end-of-file");
222 t if (yydebug != null)
223 t yydebug.discard(yyState, yyToken, yyname(yyToken),
226 . continue yyDiscarded; // leave stack alone
229 . int yyV = yyTop + 1-yyLen[yyN];
230 t if (yydebug != null)
231 t yydebug.reduce(yyState, yyStates[yyV-1], yyN, YYRules.getRule[yyN], yyLen[yyN]);
232 . yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]);
235 actions ## code from the actions within the grammar
238 . yyTop -= yyLen[yyN];
239 . yyState = yyStates[yyTop];
240 . int yyM = yyLhs[yyN];
241 . if (yyState == 0 && yyM == 0) {
242 t if (yydebug != null) yydebug.shift(0, yyFinal);
245 . yyToken = yyLex.advance() ? yyLex.token() : 0;
246 t if (yydebug != null)
247 t yydebug.lex(yyState, yyToken,yyname(yyToken), yyLex.value());
249 . if (yyToken == 0) {
250 t if (yydebug != null) yydebug.accept(yyVal);
255 . if ((yyN = yyGindex[yyM]) != 0 && (yyN += yyState) >= 0
256 . && yyN < yyTable.length && yyCheck[yyN] == yyState)
257 . yyState = yyTable[yyN];
259 . yyState = yyDgoto[yyM];
260 t if (yydebug != null) yydebug.shift(yyStates[yyTop], yyState);
266 tables ## tables for rules, default reduction, and action calls
268 epilog ## text following second %%