ArithmeticExperimental.ebnf 2.03 KB
 eckhart committed Feb 23, 2019 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ``````# Arithmetic-grammar ####################################################################### # # EBNF-Directives # ####################################################################### @ whitespace = vertical # implicit whitespace, includes any number of line feeds @ literalws = right # literals have implicit whitespace on the right hand side @ comment = /#.*/ # comments range from a '#'-character to the end of the line @ ignorecase = False # literals and regular expressions are case-sensitive @ drop = whitespace, token # drop anonymous whitespace `````` Eckhart Arnold committed Feb 24, 2019 15 `````` `````` eckhart committed Feb 23, 2019 16 17 ``````####################################################################### # `````` Eckhart Arnold committed Feb 24, 2019 18 ``````#: Expressions `````` eckhart committed Feb 23, 2019 19 20 21 ``````# ####################################################################### `````` 22 23 24 ``````expression = add | sub | term add = term "+" expression sub = term "-" expression `````` Eckhart Arnold committed Feb 24, 2019 25 `````` `````` eckhart committed Feb 23, 2019 26 27 28 `````` ####################################################################### # `````` Eckhart Arnold committed Feb 24, 2019 29 ``````#: Terms `````` eckhart committed Feb 23, 2019 30 31 32 ``````# ####################################################################### `````` 33 ``````term = mul | div | factor `````` eckhart committed Feb 28, 2019 34 ``````mul = factor "*" term `````` 35 ``````div = factor "/" term `````` Eckhart Arnold committed Feb 24, 2019 36 37 38 39 40 41 42 43 `````` ####################################################################### # #: Factors # ####################################################################### `````` eckhart committed Feb 28, 2019 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 ``````factor = [sign] [element] tail tail = seq | tail_elem seq = tail_elem tail ####################################################################### # #: Elements # ####################################################################### element = pow | atom pow = atom "^" pow atom = NUMBER | VARIABLE | group tail_elem = tail_pow | tail_atom tail_pow = fragment "^" pow tail_atom = VARIABLE | group `````` 63 64 ``````sign = PLUS | MINUS group = "(" §expression ")" `````` Eckhart Arnold committed Feb 24, 2019 65 66 67 68 69 70 71 `````` ####################################################################### # #: Tokens # ####################################################################### `````` eckhart committed Feb 23, 2019 72 `````` `````` 73 74 75 ``````PLUS = /\+/ MINUS = /-/ NUMBER = /(?:0|(?:[1-9]\d*))(?:\.\d+)?/~ `````` eckhart committed Feb 28, 2019 76 ``VARIABLE = /[i-z]/~``