Skip to content

Instantly share code, notes, and snippets.

@scientific-coder
Created October 17, 2018 11:05
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/96f96d720d42c5e2c9b9a42773b07ae9 to your computer and use it in GitHub Desktop.
Save scientific-coder/96f96d720d42c5e2c9b9a42773b07ae9 to your computer and use it in GitHub Desktop.
(def lang0-parser
(instaparse.core/parser
"prog = (spaces? expr spaces? <';'> spaces?)*
<expr> = assig | add-sub
assig = varname spaces? <'='> spaces? expr
<add-sub> = mult-div | add | sub
add = add-sub spaces? <'+'> spaces? mult-div
sub = add-sub spaces? <'-'> spaces? mult-div
<mult-div> = factor | mult |div
mult = mult-div spaces? <'*'> spaces? factor
div = mult-div spaces? <'/'> spaces? factor
<factor> = number | <'('> spaces? expr spaces? <')'> | varget |assig
<spaces> = <#'\\s+'>
number = #'-?[0-9]+'
varget = varname
varname = #'[a-zA-Z]\\w*'"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment