Skip to content

Instantly share code, notes, and snippets.

@washort
Created August 14, 2012 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save washort/3346308 to your computer and use it in GitHub Desktop.
Save washort/3346308 to your computer and use it in GitHub Desktop.
what

Parsley Tutorial

Four function calculator:

digit = anything:x ?(x in '0123456789')
number = <digit+>:ds -> int(ds)
ws = ' '*
muldiv = value:left ws ('*' value:right -> left * right
                       |'/' value:right -> left / right
                       | -> left)

expr = muldiv:left ws ('+' muldiv:right -> left + right
                        |'-' muldiv:right -> left - right
                        | -> left)
parens = '(' ws expr:e ws ')' -> e
value = ws (number | parens)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment