<start> = assignment | expr | comment | directive
expr = add-sub [comment]
comment = <#'\s*(#.*$)?'>
<add-sub> = pow-term | mul-div | add | sub | variable
add = add-sub <'+'> mul-div
sub = add-sub <'-'> mul-div
<mul-div> = pow-term | mul | div | mod
mul = mul-div <'*'> pow-term
div = mul-div <'/'> pow-term
mod = mul-div <'mod'> pow-term
<pow-term> = pow | factorial | term
pow = posterm <'^'> pow-term
factorial = posterm <'!'> <#'\s*'>
<function> = log | ln | exp | sqrt | abs | sin | cos | tan | acos | asin | atan
log = <#'\s*'> <'log('> expr <')'> <#'\s*'>
ln = <#'\s*'> <'ln('> expr <')'> <#'\s*'>
exp = <#'\s*'> <'exp('> expr <')'> <#'\s*'>
sqrt = <#'\s*'> <'sqrt('> expr <')'> <#'\s*'>
abs = <#'\s*'> <'abs('> expr <')'> <#'\s*'>
sin = <#'\s*'> <'sin('> expr <')'> <#'\s*'>
cos = <#'\s*'> <'cos('> expr <')'> <#'\s*'>
tan = <#'\s*'> <'tan('> expr <')'> <#'\s*'>
atan = <#'\s*'> <'atan('> expr <')'> <#'\s*'>
acos = <#'\s*'> <'acos('> expr <')'> <#'\s*'>
asin = <#'\s*'> <'asin('> expr <')'> <#'\s*'>
<posterm> = function | percent | scientific | number | mixed-number | variable | <#'\s*'> <'('> expr <')'> <#'\s*'>
negterm = <#'\s*'> <'-'> ( posterm | pow | factorial )
<term> = negterm | posterm
scientific = #'\s*[0-9]*\.?[0-9]+(e|E)[\-\+]?[0-9]+()\s*'
number = decimal-number | hexadecimal-number | octal-number | binary-number
<decimal-number> = #'\s*(\d+(,\d+)*(\.\d*)?|\d*\.\d+)\s*'
<hexadecimal-number> = #'\s*0x([0-9a-fA-F]+(,[0-9a-fA-F]+)*(\.[0-9a-fA-F]*)?|[0-9a-fA-F]*\.[0-9a-fA-F]+)\s*'
<octal-number> = #'\s*0o([0-7]+(,[0-7]+)*(\.[0-7]*)?|[0-7]*\.[0-7]+)\s*'
<binary-number> = #'\s*0b([01]+(,[01]+)*(\.[01]*)?|[01]*\.[01]+)\s*'
mixed-number = <#'\s*'> digits <#'\s+'> digits <'/'> digits <#'\s*'>
percent = number <'%'> <#'\s*'>
variable = #'\s*_*[a-zA-Z]+[_a-zA-Z0-9]*\s*'
toassign = #'\s*_*[a-zA-Z]+[_a-zA-Z0-9]*\s*'
assignment = toassign <#'\s*'> <'='> <#'\s*'> expr
<directive> = <#'\s*\:'> (format | base) <#'\s*'> [comment]
<format> = <#'(format|fmt)\s+'> ( format-fix | format-sci | format-norm | format-frac | format-impf )
format-fix = <#'(?i)fix(ed)?\s*'> digits
format-sci = <#'(?i)sci(entific)?\s*'> [digits]
format-norm = <#'(?i)norm(al)?\s*'> [digits]
format-frac = <#'(?i)frac(tions?)?\s*'> [digits]
format-impf = <#'(?i)imp(roper)?\s*'> [digits]
base = base-hex | base-dec | base-oct | base-bin
<base-hex> = #'(?i)hex' <#'(?i)(adecimal)?'>
<base-dec> = #'(?i)dec' <#'(?i)(imal)?'>
<base-oct> = #'(?i)oct' <#'(?i)(al)?'>
<base-bin> = #'(?i)bin' <#'(?i)(ary)?'>
digits = #'\d+'