Created
January 10, 2017 07:48
-
-
Save bakso/00be0460b6c0063aaded76b64c1af3ba to your computer and use it in GitHub Desktop.
rpn peg.js wrong version
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
{ | |
function buildBinaryExpression(op, left, right) { | |
return { | |
type: 'BinaryExpression', | |
operator: op, | |
left: left, | |
right: right | |
} | |
} | |
} | |
Expression | |
= head:Term _ tail:Term _ op:Operator { | |
return buildBinaryExpression(op, head, tail); | |
} | |
/ Term | |
Term | |
= head:Factor _ tail:Factor _ op:Operator { | |
return buildBinaryExpression(op, head, tail); | |
} | |
/ Factor | |
Factor | |
= Integer | |
/ Expression | |
Operator | |
= "+" | |
/ "-" | |
/ "*" | |
/ "/" | |
Integer "integer" | |
= [0-9]+ { | |
return parseInt(text(), 10); | |
} | |
_ "whitespace" | |
= [ ]+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment