Module:ColinTheCat/Expression/doc: Difference between revisions

From Resonite Wiki
No edit summary
No edit summary
Line 6: Line 6:


<pre>
<pre>
Expr ::= Add
Expr ::= Add
Add ::= Mul (PlusMinus Add)?
Add   ::= Mod (PlusMinus Add)?
Mul ::= Exp (MulDiv Mul)?
Mod  ::= Mul ('%' Mul)?
Pow ::= Call ('^' Call)?
Mul  ::= Pow (MulDiv Mul)?
Call ::= Var | Name ('(' Args ')')?
Pow   ::= Minus ('^' Minus)?
Var ::= Name | Num | '(' Expr ')'
Minus ::= '-'? Call
Call ::= Var | Name ('(' Args ')')?
Var   ::= Name | Num | '(' Expr ')'


Args ::= Expr (',' Expr)?
Args ::= Expr (',' Expr)?

Revision as of 13:51, 11 February 2024

EBNF Grammar

What's EBNF?

For a graphical representation, take a look at this website.

Expr  ::= Add
Add   ::= Mod (PlusMinus Add)?
Mod   ::= Mul ('%' Mul)?
Mul   ::= Pow (MulDiv Mul)?
Pow   ::= Minus ('^' Minus)?
Minus ::= '-'? Call
Call  ::= Var | Name ('(' Args ')')?
Var   ::= Name | Num | '(' Expr ')'

Args ::= Expr (',' Expr)?

PlusMinus ::= [+-]                           /* ws: explicit */
MulDiv    ::= [*/]                           /* ws: explicit */
Num       ::= ('0' | [1-9]+) ('.' [1-9]+)?   /* ws: explicit */
Name      ::= [a-z] [a-z0-9_]*               /* ws: explicit */

Example

{{#invoke:ColinTheCat/Expression|Eval
| 2 * (1 + min(10, x))
| {"x": 2}
}}

2 * (1 + min(10, x)) (x=2) evaluates to 6