1 package antlr; 2 3 9 10 import java.io.IOException ; 11 12 18 public class LLkParser extends Parser { 19 int k; 20 21 public LLkParser(int k_) { 22 k = k_; 23 } 26 27 public LLkParser(ParserSharedInputState state, int k_) { 28 k = k_; 29 inputState = state; 30 } 31 32 public LLkParser(TokenBuffer tokenBuf, int k_) { 33 k = k_; 34 setTokenBuffer(tokenBuf); 35 } 36 37 public LLkParser(TokenStream lexer, int k_) { 38 k = k_; 39 TokenBuffer tokenBuf = new TokenBuffer(lexer); 40 setTokenBuffer(tokenBuf); 41 } 42 43 50 public void consume() { 51 inputState.input.consume(); 52 } 53 54 public int LA(int i) throws TokenStreamException { 55 return inputState.input.LA(i); 56 } 57 58 public Token LT(int i) throws TokenStreamException { 59 return inputState.input.LT(i); 60 } 61 62 private void trace(String ee, String rname) throws TokenStreamException { 63 traceIndent(); 64 System.out.print(ee + rname + ((inputState.guessing > 0)?"; [guessing]":"; ")); 65 for (int i = 1; i <= k; i++) { 66 if (i != 1) { 67 System.out.print(", "); 68 } 69 System.out.print("LA(" + i + ")==" + LT(i).getText()); 70 } 71 System.out.println(""); 72 } 73 74 public void traceIn(String rname) throws TokenStreamException { 75 traceDepth += 1; 76 trace("> ", rname); 77 } 78 79 public void traceOut(String rname) throws TokenStreamException { 80 trace("< ", rname); 81 traceDepth -= 1; 82 } 83 } 84 | Popular Tags |