Module:ColinTheCat/Expression/doc: Difference between revisions

From Resonite Wiki
Created page with "<code>2 * (1 + min(10, x))</code> (x=2) evaluates to {{#invoke:ColinTheCat/Expression|Eval | 2 * (1 + min(10, x)) | {"x": 2} }}"
 
No edit summary
Line 1: Line 1:
<code>2 * (1 + min(10, x))</code> (x=2) evaluates to {{#invoke:ColinTheCat/Expression|Eval
== EBNF Grammar ==
 
''[https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form What's EBNF?]''
 
For a graphical representation, take a look at [https://rr.red-dove.com/ui this website].
 
<pre>
Expr ::= Add
Add  ::= Mul (PlusMinus Add)?
Mul  ::= Exp (MulDiv Mul)?
Pow  ::= Call ('^' 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 */
</pre>
 
== Example ==
 
<pre>
{{#invoke:ColinTheCat/Expression|Eval
| 2 * (1 + min(10, x))
| {"x": 2}
}}
</pre>
 
<code>2 * (1 + min(10, x))</code> (x=2) evaluates to
{{#invoke:ColinTheCat/Expression|Eval
| 2 * (1 + min(10, x))
| 2 * (1 + min(10, x))
| {"x": 2}
| {"x": 2}
}}
}}

Revision as of 13:17, 11 February 2024

EBNF Grammar

What's EBNF?

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

Expr ::= Add
Add  ::= Mul (PlusMinus Add)?
Mul  ::= Exp (MulDiv Mul)?
Pow  ::= Call ('^' 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