Skip to content

deeper into conditions

Light Sharp Lang edited this page Jan 10, 2024 · 6 revisions

using

Conditions can be combined, let's assume two conditions named X and Y

$X
  $Y
    foo()
  $
$

or in inline syntax:

$X$ $Y$ foo()

it means "if X is true and Y is true, then do:"

operators

i provided a lot of operators:

map < string, Tokentypes > tokens_dict = {
    { "==", Tokentypes::je },
    { "!=" , Tokentypes::jne },
    { "=True", Tokentypes::jz },
    { "=False", Tokentypes::jnz },
    { ">", Tokentypes::jg },
    { "!>", Tokentypes::jng},
    { ">=", Tokentypes::jge },
    { "!>=", Tokentypes::jnge },
    { "<", Tokentypes::jl },
    { "!<", Tokentypes::jnl },
    { "<=", Tokentypes::jle },
    { "!<=", Tokentypes::jnle }
    };

reuse of conditions

Conditions are stored into the memory of the compiler like so:

struct condition {
    string name = "";
    constant left;
    Tokentypes operator;
    constant right;
};

so when you define a condition named X like so

$X = i == 1

if a code like this is in use

int i = 1

$X = i == 1
$X$ i = 0
...code...
$X$ i = 3

the second condition will be dynamic and will look if i is still equals to 1, whatever the result of the last check

else

the else structure is made by adding ! before the name of the condition:

$condition = 1 == 1
$condition$ i = 1 """ if 1 == 1 then ... """
$!condition$ i = 0 """ if not ... """

Clone this wiki locally