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} }}"
 
 
(2 intermediate revisions by the same user not shown)
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  ::= 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 */
</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}
}}
}}

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