SkyTemple / ExplorerScript

ExplorerScript and SSBScript: Script languages for decompiled SSB (Pokémon Mystery Dungeon Explorers of Sky)
MIT License
16 stars 6 forks source link

if-else construct in const-evaluation blocks #56

Open theCapypara opened 2 months ago

theCapypara commented 2 months ago

Summary

Add a ternary if-else construct to const-evaluation expressions.

Dependencies

This needs the following features to be implemented first:

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.

Compiler Implementation

Compiler Interface Changes

None

Decompiler Changes

None

How to teach

Add to meta programming sections

Alternatives

Different syntax

Backwards compatibility

None