Created
April 23, 2012 16:50
-
-
Save cammckinnon/2472235 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* Classic example grammar, which recognizes simple arithmetic expressions like | |
* "2*(3+4)". The parser generated from this grammar then computes their value. | |
*/ | |
start | |
= additive | |
additive | |
= left:multiplicative "+" right:additive { return {op: '+', toks: [left, right]}; } | |
/ multiplicative | |
multiplicative | |
= left:primary "*" right:multiplicative { return {op: '*', toks: [left, right]}; } | |
/ primary | |
primary | |
= integer | |
/ "(" additive:additive ")" { return additive } | |
integer | |
= digits:[0-9]+ { return parseInt(digits.join("")) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment