Created
April 24, 2018 15:17
-
-
Save quadrupleslap/21afbc2dd4bc8857d6cef8e4c0302886 to your computer and use it in GitHub Desktop.
Questionable math expression grammar.
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
defn =_{ soi ~ variable ~ "=" ~ expr ~ eoi } | |
main =_{ soi ~ expr ~ eoi } | |
add = { "+" } | |
sub = { "-" } | |
mul = { "*" } | |
div = { "/" } | |
rem = { "%" } | |
exp = { "^" } | |
atom = { function ~ "(" ~ expr ~ ")" | |
| "(" ~ expr ~ ")" | |
| float | |
| variable | |
| "i" | |
} | |
fact = { atom ~ (exp ~ term)? } | |
join = { fact+ } | |
term = { (add | sub)* ~ join } | |
prod = { term ~ ((mul | div | rem) ~ term)* } | |
expr = { prod ~ ((add | sub) ~ prod)* } | |
alpha = { 'a'..'z' | 'A'..'Z' } | |
digit = { '0'..'9' } | |
float =@{ digit+ ~ ("." ~ digit+)? } | |
variable =@{ alpha } | |
function =@{ alpha ~ (alpha | digit)* } | |
whitespace = _{ " " } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment