Added ability to order the execution of dictionary adapter behaviors.
[castle.git] / Experiments / Attic / Rook / Castle.Rook.Compiler / Parser / antlr / LLkParser.cs
blob4e60ca65cb253ce1f9b327adc7246c0c44699ece
1 using System;
3 namespace antlr
5 /*ANTLR Translator Generator
6 * Project led by Terence Parr at http://www.jGuru.com
7 * Software rights: http://www.antlr.org/license.html
9 * $Id:$
13 // ANTLR C# Code Generator by Micheal Jordan
14 // Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
15 // Anthony Oguntimehin
17 // With many thanks to Eric V. Smith from the ANTLR list.
20 /*An LL(k) parser.
22 * @see antlr.Token
23 * @see antlr.TokenBuffer
24 * @see antlr.LL1Parser
26 public class LLkParser : Parser
28 internal int k;
30 public LLkParser(int k_)
32 k = k_;
34 public LLkParser(ParserSharedInputState state, int k_)
36 k = k_;
37 inputState = state;
39 public LLkParser(TokenBuffer tokenBuf, int k_)
41 k = k_;
42 setTokenBuffer(tokenBuf);
44 public LLkParser(TokenStream lexer, int k_)
46 k = k_;
47 TokenBuffer tokenBuf = new TokenBuffer(lexer);
48 setTokenBuffer(tokenBuf);
50 /*Consume another token from the input stream. Can only write sequentially!
51 * If you need 3 tokens ahead, you must consume() 3 times.
52 * <p>
53 * Note that it is possible to overwrite tokens that have not been matched.
54 * For example, calling consume() 3 times when k=2, means that the first token
55 * consumed will be overwritten with the 3rd.
57 override public void consume()
59 inputState.input.consume();
61 override public int LA(int i)
63 return inputState.input.LA(i);
65 override public IToken LT(int i)
67 return inputState.input.LT(i);
69 private void trace(string ee, string rname)
71 traceIndent();
72 Console.Out.Write(ee + rname + ((inputState.guessing > 0)?"; [guessing]":"; "));
73 for (int i = 1; i <= k; i++)
75 if (i != 1)
77 Console.Out.Write(", ");
79 if ( LT(i)!=null ) {
80 Console.Out.Write("LA(" + i + ")==" + LT(i).getText());
82 else
84 Console.Out.Write("LA(" + i + ")==ull");
87 Console.Out.WriteLine("");
89 override public void traceIn(string rname)
91 traceDepth += 1;
92 trace("> ", rname);
94 override public void traceOut(string rname)
96 trace("< ", rname);
97 traceDepth -= 1;