Created
October 17, 2018 11:19
-
-
Save scientific-coder/e139c88c6410d4ab237822ddc1a4809c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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