Add a ternary if-else construct to const-evaluation expressions.
Dependencies
This needs the following features to be implemented first:
54
Motivation
This allows basic conditional logic in const-evaluation blocks.
Examples
const FOO = ${if 3 > 2 then XYZ else "whatever"}
Language Changes
Parser and Lexer Changes
These expressions must be added to the grammar. Parenthesis may be required or optional, depending on parsability. Even if they are optional, they may be required or at least useful to use for complex expressions.
Behaviour
The new expression is defined as: if X then Y else Z, where Y will be the result of the expression if the integer X > 0, otherwise Z will be the result.
If X is not an integer, this fails.
Summary
Add a ternary if-else construct to const-evaluation expressions.
Dependencies
This needs the following features to be implemented first:
54
Motivation
This allows basic conditional logic in const-evaluation blocks.
Examples
Language Changes
Parser and Lexer Changes
These expressions must be added to the grammar. Parenthesis may be required or optional, depending on parsability. Even if they are optional, they may be required or at least useful to use for complex expressions.
Behaviour
The new expression is defined as:
if X then Y else Z
, whereY
will be the result of the expression if the integerX > 0
, otherwiseZ
will be the result. IfX
is not an integer, this fails.Compiler Implementation
Compiler Interface Changes
None
Decompiler Changes
None
How to teach
Add to meta programming sections
Alternatives
Different syntax
Backwards compatibility
None