ArithmeticRightRecursive.ebnf 1.41 KB
 eckhart committed Mar 03, 2019 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 ``````# 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 ####################################################################### # #: Structure and Components # ####################################################################### expression = add | sub | term add = term "+" expression sub = term "-" expression term = mul | div | factor mul = factor "*" term div = factor "/" term factor = [sign] (NUMBER | VARIABLE | group) sign = POSITIVE | NEGATIVE group = "(" expression ")" ####################################################################### # #: "Leaf"-Expressions # ####################################################################### POSITIVE = /[+]/ # no implicit whitespace after signs NEGATIVE = /[-]/ NUMBER = /(?:0|(?:[1-9]\d*))(?:\.\d+)?/~ VARIABLE = /[A-Za-z]/~``````