Skip to content

Instantly share code, notes, and snippets.

@4mitch
Last active July 13, 2017 18:23
Show Gist options
  • Save 4mitch/0e0f221890276ecc23fb65005d5c3cea to your computer and use it in GitHub Desktop.
Save 4mitch/0e0f221890276ecc23fb65005d5c3cea to your computer and use it in GitHub Desktop.
PEG.JS example
start =
comma
comma = left:additive "," right:comma
{ return {tag: ",", left, right}; } / additive
additive =
left:multiplicative "+" right:additive
{ return {tag: "+", left, right}; } / multiplicative
multiplicative =
left:division "*" right:multiplicative
{ return {tag: "*", left, right}; } / division
division =
left:primary "/" right:division
{ return {tag: "/", left, right}; } / primary
primary =
integer / "(" a:comma ")"
{ return a; }
integer =
digits:[0-9]+
{ return parseInt(digits.join(""), 10); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment