1 package antlr;
2
3 * <b>SOFTWARE RIGHTS</b>
5 * <p>
6 * ANTLR 2.5.0 MageLang Institute, 1998
7 * <p>
8 * We reserve no legal rights to the ANTLR--it is fully in the
9 * public domain. An individual or company may do whatever
10 * they wish with source code distributed with ANTLR or the
11 * code generated by ANTLR, including the incorporation of
12 * ANTLR, or its output, into commerical software.
13 * <p>
14 * We encourage users to develop software with ANTLR. However,
15 * we do ask that credit is given to us for developing
16 * ANTLR. By "credit", we mean that if you use ANTLR or
17 * incorporate any source code into one of your programs
18 * (commercial product, research project, or otherwise) that
19 * you acknowledge this fact somewhere in the documentation,
20 * research report, etc... If you like ANTLR and have
21 * developed a nice tool with the output, please mention that
22 * you developed it using ANTLR. In addition, we ask that the
23 * headers remain intact in our source code. As long as these
24 * guidelines are kept, we expect to continue enhancing this
25 * system and expect to make other tools available as they are
26 * completed.
27 * <p>
28 * The ANTLR gang:
29 * @version ANTLR 2.5.0 MageLang Institute, 1998
30 * @author Terence Parr, <a href=http://www.MageLang.com>MageLang Institute</a>
31 * @author <br>John Lilley, <a href=http://www.Empathy.com>Empathy Software</a>
32 */
33 *
35 * @see antlr.Token
36 * @see antlr.TokenBuffer
37 * @see antlr.LL1Parser
38 */
39
40 import java.io.IOException;
41
42 public class LLkParser extends Parser {
43 int k;
44
45
46 public LLkParser(int k_) {
47 k = k_;
48 }
51 public LLkParser(TokenBuffer tokenBuf, int k_) {
52 k = k_;
53 setTokenBuffer(tokenBuf);
54 }
55 public LLkParser(Tokenizer lexer, int k_) {
56 k = k_;
57 TokenBuffer tokenBuf = new TokenBuffer(lexer);
58 setTokenBuffer(tokenBuf);
59 }
60 * If you need 3 tokens ahead, you must consume() 3 times.
62 * <p>
63 * Note that it is possible to overwrite tokens that have not been matched.
64 * For example, calling consume() 3 times when k=2, means that the first token
65 * consumed will be overwritten with the 3rd.
66 */
67 public void consume() {
68 input.consume();
69 }
70 public int LA(int i) throws IOException {
71 return input.LA(i);
72 }
73 public Token LT(int i) throws IOException {
74 return input.LT(i);
75 }
76 private void trace(String ee, String rname) throws IOException {
77 System.out.print(ee + rname + ((guessing>0)?"; [guessing]":"; "));
78 for (int i = 1; i <= k; i++)
79 {
80 if (i != 1) {
81 System.out.print(", ");
82 }
83 System.out.print("LA(" + i + ")==" + LT(i).getText());
84 }
85 System.out.println("");
86 }
87 public void traceIn(String rname) throws IOException {
88 trace("enter ", rname);
89 }
90 public void traceOut(String rname) throws IOException {
91 trace("exit ", rname);
92 }
93 }
94