Skip to content

Instantly share code, notes, and snippets.

@mroeder
Last active December 8, 2016 22:07
Show Gist options
  • Save mroeder/7f62adb8df879a5eb8288dbbddcc663f to your computer and use it in GitHub Desktop.
Save mroeder/7f62adb8df879a5eb8288dbbddcc663f to your computer and use it in GitHub Desktop.
Arithmetic Grammar for Ohm
[
{
"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
}
]
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