11 How it Works
te_parser::evaluate()
uses a simple recursive descent parser to compile your expression into a syntax tree. For example, the expression "sin x + 1/4"
parses as:
te_parser::evaluate()
also automatically prunes constant branches. In this example, the compiled expression returned by compile()
would become:
Grammar
TinyExpr++ parses the following grammar (from lowest-to-highest operator precedence):
<list> = <expr> {(",", ";" [dependent on locale]) <expr>}
<expr> = <term> {("&" | "|") <term>}
<expr> = <term> {("<>" | "!=" | "=" | "<") | "<=") | ">" | ">=") <term>}
<expr> = <term> {("<<" | ">>") <term>}
<expr> = <term> {("+" | "-") <term>}
<term> = <factor> {("*" | "/" | "%") <factor>}
<factor> = <power> {("^" | "**") <power>}
<power> = {("-" | "+")} <base>
<base> = <constant>
| <variable>
| <function-0> {"(" ")"}
| <function-1> <power>
| <function-X> "(" <expr> {"," <expr>} ")"
| "(" <list> ")"