Language Structure¶
The following are the various language structures available within MathExpr and their structural representations.
- If Statement
- Else Statement
- Ternary Statement
- While Loop
- Repeat Until Loop
- For Loop
- Switch Statement
- Multi Subexpression Statement
- Multi Case-Consequent Statement
- Variable Definition Statement
- Vector Definition Statement
- String Definition Statement
- Range Statement
- Return Statement
If Statement¶
+-------------------------------------------------------------+
| |
| [if] ---> [(] ---> [condition] -+-> [,] -+ |
| | | |
| +---------------<---------------+ | |
| | | |
| | +------------------<------------------+ |
| | | |
| | +--> [consequent] ---> [,] ---> [alternative] ---> [)] |
| | |
| +--> [)] --+-> [{] ---> [expression*] ---> [}] --+ |
| | | |
| | +---------<----------+ |
| +----<-----+ | |
| | v |
| +--> [consequent] --> [;] -{*}-> [else-statement] |
| |
+-------------------------------------------------------------+
Else Statement¶
+-------------------------------------------------------------+
| |
| [else] -+-> [alternative] ---> [;] |
| | |
| +--> [{] ---> [expression*] ---> [}] |
| | |
| +--> [if-statement] |
| |
+-------------------------------------------------------------+
Ternary Statement¶
+-------------------------------------------------------------+
| |
| [condition] ---> [?] ---> [consequent] ---> [:] --+ |
| | |
| +------------------------<------------------------+ |
| | |
| +--> [alternative] --> [;] |
| |
+-------------------------------------------------------------+
While Loop¶
+-------------------------------------------------------------+
| |
| [while] ---> [(] ---> [condition] ---> [)] ---+ |
| | |
| +----------------------<----------------------+ |
| | |
| +--> [{] ---> [expression*] ---> [}] |
| |
+-------------------------------------------------------------+
Repeat Until Loop¶
+-------------------------------------------------------------+
| |
| [repeat] ---> [expression*] ---+ |
| | |
| +--------------<---------------+ |
| | |
| +--> [until] ---> [(] ---> [condition] --->[)] |
| |
+-------------------------------------------------------------+
For Loop¶
+-------------------------------------------------------------+
| |
| [for] ---> [(] -+-> [initialise expression] --+--+ |
| | | | |
| +------------->---------------+ v |
| | |
| +-----------------------<------------------------+ |
| | |
| +--> [;] -+-> [condition] -+-> [;] ---+ |
| | | | |
| +------->--------+ v |
| | |
| +------------------<---------+--------+ |
| | | |
| +--> [increment expression] -+-> [)] --+ |
| | |
| +------------------<-------------------+ |
| | |
| +--> [{] ---> [expression*] ---> [}] |
| |
+-------------------------------------------------------------+
Switch Statement¶
+-------------------------------------------------------------+
| |
| [switch] ---> [{] ---+ |
| | |
| +---------<----------+-----------<-----------+ |
| | | |
| +--> [case] ---> [condition] ---> [:] ---+ | |
| | | |
| +-------------------<--------------------+ | |
| | | |
| +--> [consequent] ---> [;] --------->--------+ |
| | | |
| | | |
| +--> [default] ---> [consequent] ---> [;] ---+ |
| | | |
| +---------------------<----------------------+ |
| | |
| +--> [}] |
| |
+-------------------------------------------------------------+
Multi Subexpression Statement¶
+-------------------------------------------------------------+
| |
| +--------------<---------------+ |
| | | |
| [~] ---> [{\(] -+-> [expression] -+-> [;\,] ---+ |
| | |
| +----------------<----------------+ |
| | |
| +--> [}\)] |
| |
+-------------------------------------------------------------+
Multi Case-Consequent Statement¶
+-------------------------------------------------------------+
| |
| [[*]] ---> [{] ---+ |
| | |
| +--------<--------+--------------<----------+ |
| | | |
| +--> [case] ---> [condition] ---> [:] ---+ | |
| | | |
| +-------------------<--------------------+ | |
| | | |
| +--> [consequent] ---> [;] ---+------>------+ |
| | |
| +--> [}] |
| |
+-------------------------------------------------------------+
Variable Definition Statement¶
+-------------------------------------------------------------+
| |
| [var] ---> [symbol] -+-> [:=] -+-> [expression] -+-> [;] |
| | | | |
| | +-----> [{}] -->--+ |
| | | |
| +------------->-------------+ |
| |
+-------------------------------------------------------------+
Vector Definition Statement¶
+-------------------------------------------------------------+
| |
| [var] ---> [symbol] ---> [[] ---> [constant] ---> []] --+ |
| | |
| +---------------------------<---------------------------+ |
| | |
| | +--------->---------+ |
| | | | |
| +--> [:=] ---> [{] -+-+-> [expression] -+-> [}] ---> [;] |
| | | |
| +--<--- [,] <-----+ |
| |
+-------------------------------------------------------------+
String Definition Statement¶
+-------------------------------------------------------------+
| |
| [var] --> [symbol] --> [:=] --> [str-expression] ---> [;] |
| |
+-------------------------------------------------------------+
Range Statement¶
+-------------------------------------------------------------+
| |
| +-------->--------+ |
| | | |
| [[] -+-> [expression] -+-> [:] -+-> [expression] -+--> []] |
| | | |
| +-------->--------+ |
| |
+-------------------------------------------------------------+