Created
January 31, 2020 01:43
-
-
Save cosinekitty/6866774969a73ffa07dbe5fb8a50267a to your computer and use it in GitHub Desktop.
Parses the 'expr' rule in the BNF grammar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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