# # Algebraic expressions # --------------------- # # These EBNF rules describe the typical syntax of an # algebraic expression that can involve numbers, # variables, functions and vectors. Examples: # # 3.141592 * 1.45 + 6.4E-2 # a*(-b + c) - 2*pi # sqrt(b*b - 4*a*c) # (x_1*x_2 + y_1*y_2 + z_1*z_2) / cos(alpha) # [[m11,m12,m13], [m21,m22,m23], [m31,m32,m33]] * V # ################################################## # Rules of the parser that evaluate the symbols # returned from the scanner. ################################################## expression = [plus|minus] term { (plus|minus) term }; term = factor { (times|divide) factor }; factor = integer | real | variable | function | matrix | lround expression rround; variable = identifier; function = identifier lround expression {comma expression} rround; matrix = lsquare expression {comma expression} rsquare; ################################################## # List of the symbols returned by the scanner, # also known as "lexer". Linear white spaces # between these symbols will be implicitly ignored # by the scanner, avoiding to clutter these # definitions with unnecessary details. ################################################## lround ="("; rround =")"; plus ="+"; minus ="-"; times ="*"; divide ="/"; lsquare="["; rsquare="]"; comma =","; integer = digits; real = digits (real_decimals | real_scale | real_decimals real_scale); identifier = letter {digit | letter | "_"}; ################################################## # Sub-rules used to define the lexer. ################################################## digit = "0".."9"; digits = digit {digit}; real_decimals = "." digits; real_scale = ("E"|"e") ["+"|"-"] digits; letter = "a".."z" | "A".."Z";