# 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 = term { (PLUS|MINUS) term} term = factor { (DIV|MUL) factor} factor = [sign] ( NUMBER | VARIABLE | group ) sign = POSITIVE | NEGATIVE group = "(" expression ")" ####################################################################### # #: "Leaf"-Expressions # ####################################################################### PLUS = "+" MINUS = "-" MUL = "*" | &factor # TODO: higher precedence of &factor DIV = "/" POSITIVE = /[+]/ # no implicit whitespace after signs NEGATIVE = /[-]/ NUMBER = /(?:0|(?:[1-9]\d*))(?:\.\d+)?/~ VARIABLE = /[A-Za-z]/~