-
-
Save rtoal/57f1e2569bb295b3cff411bfcc557f32 to your computer and use it in GitHub Desktop.
Arithmetic Grammar for Ohm
This file contains 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
[ | |
{ | |
"text": "2 * (42 - 1) / 9", | |
"startRule": "Exp", | |
"shouldMatch": true | |
}, | |
{ | |
"text": "1+2*3", | |
"startRule": "Exp", | |
"shouldMatch": true | |
}, | |
{ | |
"text": "I CAN HAS CHEEZBURGER?", | |
"startRule": "Exp", | |
"shouldMatch": false | |
}, | |
{ | |
"text": " ( \t123 ) ", | |
"startRule": "Exp", | |
"shouldMatch": true | |
}, | |
{ | |
"text": "(2+4)*7", | |
"startRule": "Exp", | |
"shouldMatch": true | |
} | |
] |
This file contains 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
Arithmetic { | |
Exp | |
= AddExp | |
AddExp | |
= AddExp "+" MulExp -- plus | |
| AddExp "-" MulExp -- minus | |
| MulExp | |
MulExp | |
= MulExp "*" ExpExp -- times | |
| MulExp "/" ExpExp -- divide | |
| ExpExp | |
ExpExp | |
= PriExp "^" ExpExp -- power | |
| PriExp | |
PriExp | |
= "(" Exp ")" -- paren | |
| "+" PriExp -- pos | |
| "-" PriExp -- neg | |
| ident | |
| number | |
ident (an identifier) | |
= letter alnum* | |
number (a number) | |
= digit* "." digit+ -- fract | |
| digit+ -- whole | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment