Skip to content

Instantly share code, notes, and snippets.

@scientific-coder
Created October 17, 2018 10:57
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 scientific-coder/efad2293535b715e3fba175f27df3ed6 to your computer and use it in GitHub Desktop.
Save scientific-coder/efad2293535b715e3fba175f27df3ed6 to your computer and use it in GitHub Desktop.
(def arith-parser
(instaparse.core/parser
"prog = spaces? add-sub spaces?
<add-sub> = mult-div | add | sub
add = add-sub spaces? <'+'> spaces? mult-div
sub = add-sub spaces? <'-'> spaces? mult-div
<mult-div> = term | mult | div
mult = mult-div spaces? <'*'> spaces? term
div = mult-div spaces? <'/'> spaces? term
<term> = number | <'('> add-sub <')'>
<spaces> = <#'\\s'+>
number = #'-?[0-9]+'"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment