Skip to content

Instantly share code, notes, and snippets.

Created November 14, 2009 21:56
Show Gist options
  • Save anonymous/234804 to your computer and use it in GitHub Desktop.
Save anonymous/234804 to your computer and use it in GitHub Desktop.
void Operand()
{
if(matches(TokenId.Identifier, TokenId.LiteralValue))
{
match(TokenId.Identifier, TokenId.LiteralValue);
}
else
Expr();
}
void Expr()
{
match(TokenId.Plus, TokenId.Minus, ...);
Operand();
Operand();
}
// "matches" should verify that the lookahead is one of the list provided
// as its argument. If it is, it should return true. otherwise false.
// "match" should verify that the lookahead is one of the list provided
// as its argument. It should consume the token if it matches, and set
// the lookahead to the next token from the string. If it doesn't match
// it should throw and give a message that the parse failed while expecting
// one of the tokens passed as the argument (in a normal parser).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment