/** * It uses "currentToken" and "expectedTokenSequences" to generate a parse * error message and returns it. If this object has been created * due to a parse error, and you do not catch it (it gets thrown * from the parser) the correct error message * gets displayed. */ private static string initialise(IrToken currentToken, int[][] expectedTokenSequences, string[] tokenImage) { string eol = Environment.NewLine; StringBuilder expected = new StringBuilder(); int maxSize = 0; for (int i = 0; i < expectedTokenSequences.Length; i++) { if (maxSize < expectedTokenSequences[i].Length) { maxSize = expectedTokenSequences[i].Length; } for (int j = 0; j < expectedTokenSequences[i].Length; j++) { expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(' '); } if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0) { expected.Append("..."); } expected.Append(eol).Append(" "); } string retval = "Encountered \""; IrToken tok = currentToken.next; for (int i = 0; i < maxSize; i++) { if (i != 0) retval += " "; if (tok.kind == 0) { retval += tokenImage[0]; break; } retval += " " + IrParserConstants.tokenImage[(int)tok.kind]; retval += " \""; retval += add_escapes(tok.image); retval += " \""; tok = tok.next; } retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += "." + eol; if (expectedTokenSequences.Length == 1) { retval += "Was expecting:" + eol + " "; } else { retval += "Was expecting one of:" + eol + " "; } retval += expected.ToString(); return retval; }
static void TokenLexicalActions(IrToken matchedToken) { switch(jjmatchedKind) { case RegExpId.INTVAL : image.Append(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); try { int.Parse(matchedToken.image); } catch (Exception e) { throw new TokenMgrError("Lexical error at line " + matchedToken.beginLine + ", column " + matchedToken.beginColumn + ". Integer value over 2^31-1", 0); } break; case RegExpId.STRVAL: image.Append(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); if (matchedToken.image.Length > 257) throw new TokenMgrError("Lexical error at line " + matchedToken.beginLine + ", column " + matchedToken.beginColumn + ". String length over 255", 0); break; case RegExpId.ID: image.Append(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); if (matchedToken.image.Length > 255) throw new TokenMgrError("Lexical error at line " + matchedToken.beginLine + ", column " + matchedToken.beginColumn + ". Id length over 255", 0); break; default : break; } }
/** * This constructor is used by the method "generateParseException" * in the generated parser. Calling this constructor generates * a new object of this type with the fields "currentToken", * "expectedTokenSequences", and "tokenImage" set. */ public IrParseException(IrToken currentTokenVal, int[][] expectedTokenSequencesVal, string[] tokenImageVal) : base(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)) { currentToken = currentTokenVal; expectedTokenSequences = expectedTokenSequencesVal; tokenImage = tokenImageVal; }
/** Constructor with generated Token Manager. */ public irParser(irParserTokenManager tm) { if (jj_initialized_once) { Console.Out.WriteLine("ERROR: Second call to constructor of static parser. "); Console.Out.WriteLine(" You must either use ReInit() or set the JavaCC option STATIC to false"); Console.Out.WriteLine(" during parser generation."); throw new Error(); } jj_initialized_once = true; token_source = tm; token = new IrToken(); jj_ntk = RegExpId.UNDEFINED; jj_gen = 0; for (int i = 0; i < 9; i++) jj_la1[i] = -1; }
/** Reinitialise. */ public void ReInit(irParserTokenManager tm) { token_source = tm; token = new IrToken(); jj_ntk = RegExpId.UNDEFINED; jj_gen = 0; for (int i = 0; i < 9; i++) jj_la1[i] = -1; }
private static RegExpId jj_ntk_fn() { if ((jj_nt = token.next) == null) //return (jj_ntk = (token.next = token_source.getNextToken()).kind); return (jj_ntk = (token.next = IrParserTokenManager.getNextToken()).kind); else return (jj_ntk = jj_nt.kind); }
/** Constructor. */ public irParser(/* java.io.Reader */ InputStreamReader stream) { if (jj_initialized_once) { Console.Out.WriteLine("ERROR: Second call to constructor of static parser. "); Console.Out.WriteLine(" You must either use ReInit() or set the JavaCC option STATIC to false"); Console.Out.WriteLine(" during parser generation."); throw new Error(); } jj_initialized_once = true; jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new irParserTokenManager(jj_input_stream); token = new IrToken(); jj_ntk = RegExpId.UNDEFINED; jj_gen = 0; for (int i = 0; i < 9; i++) jj_la1[i] = -1; }
/* throws ParseException */ private static IrToken jj_consume_token(IrParserConstants.RegExpId kind) { IrToken oldToken; if ((oldToken = token).next != null) token = token.next; else { //token = token.next = token_source.getNextToken(); token.next = IrParserTokenManager.getNextToken(); token = token.next; } jj_ntk = RegExpId.UNDEFINED; if (token.kind == kind) { jj_gen++; return token; } token = oldToken; jj_kind = kind; throw generateParseException(); }
/** Reinitialise. */ public static void ReInit(/* java.io.Reader */ StreamReader streamReader) { jj_input_stream.ReInit(streamReader, 1, 1); //token_source.ReInit(jj_input_stream); IrParserTokenManager.ReInit(jj_input_stream); token = new IrToken(); jj_ntk = RegExpId.UNDEFINED; jj_gen = 0; for (int i = 0; i < 9; i++) jj_la1[i] = -1; }
/** Reinitialise. */ public static void ReInit(Stream stream, Encoding encoding) { try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } //token_source.ReInit(jj_input_stream); IrParserTokenManager.ReInit(jj_input_stream); token = new IrToken(); jj_ntk = RegExpId.UNDEFINED; jj_gen = 0; for (int i = 0; i < 9; i++) jj_la1[i] = -1; }
/** Get the next Token. */ public static IrToken getNextToken() { if (token.next != null) token = token.next; else //token = token.next = token_source.getNextToken(); token = token.next = IrParserTokenManager.getNextToken(); jj_ntk = RegExpId.UNDEFINED; jj_gen++; return token; }
/** Constructor with InputStream and supplied encoding */ public IrParser(Stream stream, Encoding encoding) { if (jj_initialized_once) { ReInit(stream, encoding); //Console.Out.WriteLine("ERROR: Second call to constructor of static parser. "); //Console.Out.WriteLine(" You must either use ReInit() or set the JavaCC option STATIC to false"); //Console.Out.WriteLine(" during parser generation."); //throw new Error(); } else { jj_initialized_once = true; try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } token_source = new IrParserTokenManager(jj_input_stream); } token = new IrToken(); jj_ntk = RegExpId.UNDEFINED; jj_gen = 0; for (int i = 0; i < 9; i++) jj_la1[i] = -1; }