Wiki

Clone wiki

mikulas / mexpr / syntax

Expression Syntax

Operators

Supported operators are:

Aritmetic operators are + - * ^ where ^ is the power. Note there are also logical operators but they are represented with functions, like less, greater, between, sign. Multiplication with such function causes the expression is nonzero only when result of the function is nonzero (usually only 0 and 1 values are used).

Number

Number can have prefix + or -. Besides normal format also the scientific is supported. Format is <before>.<frac>E[<sign>]<number>.

Function

Function has format name([pars]). Arguments are separated by comma.

Metric Prefix

When enabled by ParserConfig.withDefaultMetricPrefixes() the metric prefixes can be used. Despite the name prefix they are written behind the number, for example 1.2m. Besides default prefixes also custom prefixes are supported. They can be also set to ParserConfig.

Default prefixes with factors when enabled are:

T 1000000000000.0
G 1000000000.0
M 1000000.0
k 1000.0
m 0.001
u 0.000001
n 0.000000001
p 0.000000000001
Hence 3k is 3000, 2u is 0.000002,...

Example

Example using all operators:

-5 * sin(x / 2.3 * e ^ (x + 1k)) - 1.25E-10

Syntax (BNF)

expr -> term [ ('+' | '-') term ]*
term -> factor [ ('*' | '/') factor ]*
factor -> negation [ '^' negation ]*
negation -> ('+' | '-') base | base
base -> identifier'('')' | identifier'(' expr [ ',' expr ]* ')' | '(' expr ')' | identifier | number metrix_prefix | number

Updated