System.Drawing: added email to icon and test file headers
[mono.git] / mcs / jay / skeleton.cs
1 #       jay skeleton
2
3 #       character in column 1 determines outcome...
4 #               # is a comment
5 #               . is copied
6 #               t is copied as //t if -t is set
7 #       other lines are interpreted to call jay procedures
8
9 .// created by jay 0.7 (c) 1998 Axel.Schreiner@informatik.uni-osnabrueck.de
10 .
11  prolog         ## %{ ... %} prior to the first %%
12
13 .
14 .  /** error output stream.
15 .      It should be changeable.
16 .    */
17 .  public System.IO.TextWriter ErrorOutput = System.Console.Out;
18 .
19 .  /** simplified error message.
20 .      @see <a href="#yyerror(java.lang.String, java.lang.String[])">yyerror</a>
21 .    */
22 .  public void yyerror (string message) {
23 .    yyerror(message, null);
24 .  }
25 .
26 .  /* An EOF token */
27 .  public int eof_token;
28 .
29 .  /** (syntax) error message.
30 .      Can be overwritten to control message format.
31 .      @param message text to be displayed.
32 .      @param expected vector of acceptable tokens, if available.
33 .    */
34 .  public void yyerror (string message, string[] expected) {
35 .    if ((yacc_verbose_flag > 0) && (expected != null) && (expected.Length  > 0)) {
36 .      ErrorOutput.Write (message+", expecting");
37 .      for (int n = 0; n < expected.Length; ++ n)
38 .        ErrorOutput.Write (" "+expected[n]);
39 .        ErrorOutput.WriteLine ();
40 .    } else
41 .      ErrorOutput.WriteLine (message);
42 .  }
43 .
44 .  /** debugging support, requires the package jay.yydebug.
45 .      Set to null to suppress debugging messages.
46 .    */
47 t  internal yydebug.yyDebug debug;
48 .
49  debug                  ## tables for debugging support
50 .
51 .  /** index-checked interface to yyNames[].
52 .      @param token single character or %token value.
53 .      @return token name or [illegal] or [unknown].
54 .    */
55 t  public static string yyname (int token) {
56 t    if ((token < 0) || (token > yyNames.Length)) return "[illegal]";
57 t    string name;
58 t    if ((name = yyNames[token]) != null) return name;
59 t    return "[unknown]";
60 t  }
61 .
62 .  int yyExpectingState;
63 .  /** computes list of expected tokens on error by tracing the tables.
64 .      @param state for which to compute the list.
65 .      @return list of token names.
66 .    */
67 .  protected int [] yyExpectingTokens (int state){
68 .    int token, n, len = 0;
69 .    bool[] ok = new bool[yyNames.Length];
70 .    if ((n = yySindex[state]) != 0)
71 .      for (token = n < 0 ? -n : 0;
72 .           (token < yyNames.Length) && (n+token < yyTable.Length); ++ token)
73 .        if (yyCheck[n+token] == token && !ok[token] && yyNames[token] != null) {
74 .          ++ len;
75 .          ok[token] = true;
76 .        }
77 .    if ((n = yyRindex[state]) != 0)
78 .      for (token = n < 0 ? -n : 0;
79 .           (token < yyNames.Length) && (n+token < yyTable.Length); ++ token)
80 .        if (yyCheck[n+token] == token && !ok[token] && yyNames[token] != null) {
81 .          ++ len;
82 .          ok[token] = true;
83 .        }
84 .    int [] result = new int [len];
85 .    for (n = token = 0; n < len;  ++ token)
86 .      if (ok[token]) result[n++] = token;
87 .    return result;
88 .  }
89 .  protected string[] yyExpecting (int state) {
90 .    int [] tokens = yyExpectingTokens (state);
91 .    string [] result = new string[tokens.Length];
92 .    for (int n = 0; n < tokens.Length;  n++)
93 .      result[n++] = yyNames[tokens [n]];
94 .    return result;
95 .  }
96 .
97 .  /** the generated parser, with debugging messages.
98 .      Maintains a state and a value stack, currently with fixed maximum size.
99 .      @param yyLex scanner.
100 .      @param yydebug debug message writer implementing yyDebug, or null.
101 .      @return result of the last reduction, if any.
102 .      @throws yyException on irrecoverable parse error.
103 .    */
104 .  internal Object yyparse (yyParser.yyInput yyLex, Object yyd)
105 .                                {
106 t    this.debug = (yydebug.yyDebug)yyd;
107 .    return yyparse(yyLex);
108 .  }
109 .
110 .  /** initial size and increment of the state/value stack [default 256].
111 .      This is not final so that it can be overwritten outside of invocations
112 .      of yyparse().
113 .    */
114 .  protected int yyMax;
115 .
116 .  /** executed at the beginning of a reduce action.
117 .      Used as $$ = yyDefault($1), prior to the user-specified action, if any.
118 .      Can be overwritten to provide deep copy, etc.
119 .      @param first value for $1, or null.
120 .      @return first.
121 .    */
122 .  protected Object yyDefault (Object first) {
123 .    return first;
124 .  }
125 .
126 .       static int[] global_yyStates;
127 .       static object[] global_yyVals;
128 .       protected bool use_global_stacks;
129 .       object[] yyVals;                                        // value stack
130 .       object yyVal;                                           // value stack ptr
131 .       int yyToken;                                            // current input
132 .       int yyTop;
133 .
134 .  /** the generated parser.
135 .      Maintains a state and a value stack, currently with fixed maximum size.
136 .      @param yyLex scanner.
137 .      @return result of the last reduction, if any.
138 .      @throws yyException on irrecoverable parse error.
139 .    */
140 .  internal Object yyparse (yyParser.yyInput yyLex)
141 .  {
142 .    if (yyMax <= 0) yyMax = 256;               // initial size
143 .    int yyState = 0;                   // state stack ptr
144 .    int [] yyStates;                   // state stack 
145 .    yyVal = null;
146 .    yyToken = -1;
147 .    int yyErrorFlag = 0;                               // #tks to shift
148 .       if (use_global_stacks && global_yyStates != null) {
149 .               yyVals = global_yyVals;
150 .               yyStates = global_yyStates;
151 .   } else {
152 .               yyVals = new object [yyMax];
153 .               yyStates = new int [yyMax];
154 .               if (use_global_stacks) {
155 .                       global_yyVals = yyVals;
156 .                       global_yyStates = yyStates;
157 .               }
158 .       }
159 .
160  local          ## %{ ... %} after the first %%
161
162 .    /*yyLoop:*/ for (yyTop = 0;; ++ yyTop) {
163 .      if (yyTop >= yyStates.Length) {                  // dynamically increase
164 .        global::System.Array.Resize (ref yyStates, yyStates.Length+yyMax);
165 .        global::System.Array.Resize (ref yyVals, yyVals.Length+yyMax);
166 .      }
167 .      yyStates[yyTop] = yyState;
168 .      yyVals[yyTop] = yyVal;
169 t      if (debug != null) debug.push(yyState, yyVal);
170 .
171 .      /*yyDiscarded:*/ while (true) {  // discarding a token does not change stack
172 .        int yyN;
173 .        if ((yyN = yyDefRed[yyState]) == 0) {  // else [default] reduce (yyN)
174 .          if (yyToken < 0) {
175 .            yyToken = yyLex.advance() ? yyLex.token() : 0;
176
177 t            if (debug != null)
178 t              debug.lex(yyState, yyToken, yyname(yyToken), yyLex.value());
179 .          }
180 .          if ((yyN = yySindex[yyState]) != 0 && ((yyN += yyToken) >= 0)
181 .              && (yyN < yyTable.Length) && (yyCheck[yyN] == yyToken)) {
182 t            if (debug != null)
183 t              debug.shift(yyState, yyTable[yyN], yyErrorFlag-1);
184 .            yyState = yyTable[yyN];            // shift to yyN
185 .            yyVal = yyLex.value();
186 .            yyToken = -1;
187 .            if (yyErrorFlag > 0) -- yyErrorFlag;
188 .            goto continue_yyLoop;
189 .          }
190 .          if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0
191 .              && yyN < yyTable.Length && yyCheck[yyN] == yyToken)
192 .            yyN = yyTable[yyN];                        // reduce (yyN)
193 .          else
194 .            switch (yyErrorFlag) {
195 .  
196 .            case 0:
197 .              yyExpectingState = yyState;
198 .              // yyerror(String.Format ("syntax error, got token `{0}'", yyname (yyToken)), yyExpecting(yyState));
199 t              if (debug != null) debug.error("syntax error");
200 .              if (yyToken == 0 /*eof*/ || yyToken == eof_token) throw new yyParser.yyUnexpectedEof ();
201 .              goto case 1;
202 .            case 1: case 2:
203 .              yyErrorFlag = 3;
204 .              do {
205 .                if ((yyN = yySindex[yyStates[yyTop]]) != 0
206 .                    && (yyN += Token.yyErrorCode) >= 0 && yyN < yyTable.Length
207 .                    && yyCheck[yyN] == Token.yyErrorCode) {
208 t                  if (debug != null)
209 t                    debug.shift(yyStates[yyTop], yyTable[yyN], 3);
210 .                  yyState = yyTable[yyN];
211 .                  yyVal = yyLex.value();
212 .                  goto continue_yyLoop;
213 .                }
214 t                if (debug != null) debug.pop(yyStates[yyTop]);
215 .              } while (-- yyTop >= 0);
216 t              if (debug != null) debug.reject();
217 .              throw new yyParser.yyException("irrecoverable syntax error");
218 .  
219 .            case 3:
220 .              if (yyToken == 0) {
221 t                if (debug != null) debug.reject();
222 .                throw new yyParser.yyException("irrecoverable syntax error at end-of-file");
223 .              }
224 t              if (debug != null)
225 t                debug.discard(yyState, yyToken, yyname(yyToken),
226 t                                                       yyLex.value());
227 .              yyToken = -1;
228 .              goto continue_yyDiscarded;               // leave stack alone
229 .            }
230 .        }
231 .        int yyV = yyTop + 1-yyLen[yyN];
232 t        if (debug != null)
233 t          debug.reduce(yyState, yyStates[yyV-1], yyN, YYRules.getRule (yyN), yyLen[yyN]);
234 .        yyVal = yyV > yyTop ? null : yyVals[yyV]; // yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]);
235 .        switch (yyN) {
236
237  actions                ## code from the actions within the grammar
238
239 .        }
240 .        yyTop -= yyLen[yyN];
241 .        yyState = yyStates[yyTop];
242 .        int yyM = yyLhs[yyN];
243 .        if (yyState == 0 && yyM == 0) {
244 t          if (debug != null) debug.shift(0, yyFinal);
245 .          yyState = yyFinal;
246 .          if (yyToken < 0) {
247 .            yyToken = yyLex.advance() ? yyLex.token() : 0;
248                 
249 t            if (debug != null)
250 t               debug.lex(yyState, yyToken,yyname(yyToken), yyLex.value());
251 .          }
252 .          if (yyToken == 0) {
253 t            if (debug != null) debug.accept(yyVal);
254 .            return yyVal;
255 .          }
256 .          goto continue_yyLoop;
257 .        }
258 .        if (((yyN = yyGindex[yyM]) != 0) && ((yyN += yyState) >= 0)
259 .            && (yyN < yyTable.Length) && (yyCheck[yyN] == yyState))
260 .          yyState = yyTable[yyN];
261 .        else
262 .          yyState = yyDgoto[yyM];
263 t        if (debug != null) debug.shift(yyStates[yyTop], yyState);
264 .        goto continue_yyLoop;
265 .      continue_yyDiscarded: ;  // implements the named-loop continue: 'continue yyDiscarded'
266 .      }
267 .    continue_yyLoop: ;         // implements the named-loop continue: 'continue yyLoop'
268 .    }
269 .  }
270 .
271  tables                 ## tables for rules, default reduction, and action calls
272 .
273  epilog                 ## text following second %%
274 .namespace yydebug {
275 .        using System;
276 .        internal interface yyDebug {
277 .                void push (int state, Object value);
278 .                void lex (int state, int token, string name, Object value);
279 .                void shift (int from, int to, int errorFlag);
280 .                void pop (int state);
281 .                void discard (int state, int token, string name, Object value);
282 .                void reduce (int from, int to, int rule, string text, int len);
283 .                void shift (int from, int to);
284 .                void accept (Object value);
285 .                void error (string message);
286 .                void reject ();
287 .        }
288 .        
289 .        class yyDebugSimple : yyDebug {
290 .                void println (string s){
291 .                        Console.Error.WriteLine (s);
292 .                }
293 .                
294 .                public void push (int state, Object value) {
295 .                        println ("push\tstate "+state+"\tvalue "+value);
296 .                }
297 .                
298 .                public void lex (int state, int token, string name, Object value) {
299 .                        println("lex\tstate "+state+"\treading "+name+"\tvalue "+value);
300 .                }
301 .                
302 .                public void shift (int from, int to, int errorFlag) {
303 .                        switch (errorFlag) {
304 .                        default:                               // normally
305 .                                println("shift\tfrom state "+from+" to "+to);
306 .                                break;
307 .                        case 0: case 1: case 2:                // in error recovery
308 .                                println("shift\tfrom state "+from+" to "+to
309 .                                            +"\t"+errorFlag+" left to recover");
310 .                                break;
311 .                        case 3:                                // normally
312 .                                println("shift\tfrom state "+from+" to "+to+"\ton error");
313 .                                break;
314 .                        }
315 .                }
316 .                
317 .                public void pop (int state) {
318 .                        println("pop\tstate "+state+"\ton error");
319 .                }
320 .                
321 .                public void discard (int state, int token, string name, Object value) {
322 .                        println("discard\tstate "+state+"\ttoken "+name+"\tvalue "+value);
323 .                }
324 .                
325 .                public void reduce (int from, int to, int rule, string text, int len) {
326 .                        println("reduce\tstate "+from+"\tuncover "+to
327 .                                    +"\trule ("+rule+") "+text);
328 .                }
329 .                
330 .                public void shift (int from, int to) {
331 .                        println("goto\tfrom state "+from+" to "+to);
332 .                }
333 .                
334 .                public void accept (Object value) {
335 .                        println("accept\tvalue "+value);
336 .                }
337 .                
338 .                public void error (string message) {
339 .                        println("error\t"+message);
340 .                }
341 .                
342 .                public void reject () {
343 .                        println("reject");
344 .                }
345 .                
346 .        }
347 .}
348 .// %token constants
349 . class Token {
350  tokens public const int
351 . }
352 . namespace yyParser {
353 .  using System;
354 .  /** thrown for irrecoverable syntax errors and stack overflow.
355 .    */
356 .  internal class yyException : System.Exception {
357 .    public yyException (string message) : base (message) {
358 .    }
359 .  }
360 .  internal class yyUnexpectedEof : yyException {
361 .    public yyUnexpectedEof (string message) : base (message) {
362 .    }
363 .    public yyUnexpectedEof () : base ("") {
364 .    }
365 .  }
366 .
367 .  /** must be implemented by a scanner object to supply input to the parser.
368 .    */
369 .  internal interface yyInput {
370 .    /** move on to next token.
371 .        @return false if positioned beyond tokens.
372 .        @throws IOException on input error.
373 .      */
374 .    bool advance (); // throws java.io.IOException;
375 .    /** classifies current token.
376 .        Should not be called if advance() returned false.
377 .        @return current %token or single character.
378 .      */
379 .    int token ();
380 .    /** associated with current token.
381 .        Should not be called if advance() returned false.
382 .        @return value for token().
383 .      */
384 .    Object value ();
385 .  }
386 . }
387 .} // close outermost namespace, that MUST HAVE BEEN opened in the prolog