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