Skip to content

Instantly share code, notes, and snippets.

@bakso
Created January 10, 2017 07:48
Show Gist options
  • Save bakso/00be0460b6c0063aaded76b64c1af3ba to your computer and use it in GitHub Desktop.
Save bakso/00be0460b6c0063aaded76b64c1af3ba to your computer and use it in GitHub Desktop.
rpn peg.js wrong version
{
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