Skip to content

Instantly share code, notes, and snippets.

@scientific-coder
Created October 17, 2018 11:19
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/e139c88c6410d4ab237822ddc1a4809c to your computer and use it in GitHub Desktop.
Save scientific-coder/e139c88c6410d4ab237822ddc1a4809c to your computer and use it in GitHub Desktop.
(def lang1-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 | argument
varname = #'[a-zA-Z]\\w*'
argument= <'%'>#'[0-9]+'"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment