Skip to content

Instantly share code, notes, and snippets.

@cosinekitty
Created January 31, 2020 01:43
Show Gist options
  • Save cosinekitty/6866774969a73ffa07dbe5fb8a50267a to your computer and use it in GitHub Desktop.
Save cosinekitty/6866774969a73ffa07dbe5fb8a50267a to your computer and use it in GitHub Desktop.
Parses the 'expr' rule in the BNF grammar.
ParseExpr() {
// expr ::= mulexpr { addop mulexpr }
let expr = this.ParseMulExpr();
let optoken;
while (optoken = this.NextTokenIs(['+', '-'])) {
const right = this.ParseMulExpr();
if (optoken.text === '+') {
expr = new Expression_Add(optoken, expr, right);
} else {
expr = new Expression_Subtract(optoken, expr, right);
}
}
return expr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment