Module:ColinTheCat/Expression/doc: Difference between revisions

From Resonite Wiki
No edit summary
 
Line 13: Line 13:
Minus ::= '-'? Call
Minus ::= '-'? Call
Call  ::= Var | Name ('(' Args ')')?
Call  ::= Var | Name ('(' Args ')')?
Var  ::= Name | Num | '(' Expr ')'
Var  ::= Name | Num | Str | '(' Expr ')'


Args ::= Expr (',' Expr)?
Args ::= Expr (',' Expr)?
Line 19: Line 19:
PlusMinus ::= [+-]                          /* ws: explicit */
PlusMinus ::= [+-]                          /* ws: explicit */
MulDiv    ::= [*/]                          /* ws: explicit */
MulDiv    ::= [*/]                          /* ws: explicit */
Num      ::= ('0' | [1-9]+) ('.' [1-9]+)?  /* ws: explicit */
Num      ::= ('0' | [1-9]+) ('.' [0-9]+)?  /* ws: explicit */
Str      ::= '"' [^"]* '"'                  /* ws: explicit */
Name      ::= [a-z] [a-z0-9_]*              /* ws: explicit */
Name      ::= [a-z] [a-z0-9_]*              /* ws: explicit */
</pre>
</pre>

Latest revision as of 20:05, 12 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 | Str | '(' Expr ')'

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

PlusMinus ::= [+-]                           /* ws: explicit */
MulDiv    ::= [*/]                           /* ws: explicit */
Num       ::= ('0' | [1-9]+) ('.' [0-9]+)?   /* ws: explicit */
Str       ::= '"' [^"]* '"'                  /* 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