private void parseFile(Context ctx) { while (!l.eof()) { if (lookAhead.TokenType == Lexer.TOKEN_DEFINE) { accept(); Lexer.Token token = match(Lexer.TOKEN_ID); match('='); Expression e = expr(); match(';'); ctx.AddExpression(token.strToken, e); } else if (lookAhead.TokenType == Lexer.TOKEN_LET) { accept(); Lexer.Token token = match(Lexer.TOKEN_ID); match('='); Lexer.Token number = match(Lexer.TOKEN_NUMBER); match(';'); ctx.AddConstant(token.strToken, number.numToken); } else { throw UnexpectedToken(); } } }
private Lexer.Token match(int Token_type) { Lexer.Token retVal = lookAhead; if (lookAhead.TokenType == Token_type) { accept(); } else { throw new Exception(String.Format("Expect {0}, got {1}", Lexer.GetTokenTypeName(Token_type), Lexer.GetTokenTypeName(lookAhead.TokenType))); } return(retVal); }