# 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]/~