Grammar
This article presents the supported grammar and syntax of the expressions.
Overview
All classic numeric and boolean functions are supported:
- Adding ("+")
- Substracting ("−")
- Multiplication ("*")
- Division ("/")
- Modulo ("%")
- Logical OR ("||")
- Exclusive Logical OR ("^")
- Logical AND ("&&")
- Logical NOT ("!")
- Numeric comparisons ("<", ">", "<=", ">=", "!=", "==")
- Parenthesis
Additionally:
- There is no limit to the level of imbrication of functions
- Operators priority is not taken into account. For example, you should write "(a * 2) + b, and not "a * 2 + b"
Syntax
Expressions types
Expresions use the following syntax:
- There are a lot of default functions, such as classic numeric functions (addition, substraction, etc..) and mathematical functions (sin, cos, etc...). For example:
- The result of "1+2" is 3
- The result of "sin(2)" is the sinus of 2
- Expressions can have one or several arguments
- Expressions can use variables and constants. For example, the result of "a + b" depends on the values of a and b, which can be variables or constants
Affectations
It is possible to use affectations in expressions. For example, for the expression "b=2*a":
- The result is "2*a"
- The value of 2*a is affected to b
Post−increment operator
Using a post−increment operator as in C is supported. For example:
a−−; // if a == 1, return 0
b++; // if b == 1, return 2
Smart−assembler operator
Using a smart−assembler operator as in C is supported. For example:
a −=2; // if a == 2, return 0
b +=3; // if b == 2, return 5
c *= 2; // if c == 4, return 8
d /= 2; // if d == 4, return 2
Code blocks
Code blocks are expressions separated by semi−colons (";"). The result of the block of code if the result of the last expression in the list, but the previous expressions will also be evaluated. For example, for the expression "a=2;b=2*a":
- The result is 4
- The value of b is 4
- The value of a is 2
The "return" keyword can be used to clarify expressions. For example, the following expression will have the same effect as the previous one: "a=2;b=2*a; return b". It is also possible in this case to write "a=2; return 2*a" if we don't want to change the value of b. Note that it is possible to omit the last ";".
Local variables
It is possible to use local variables in expressions. For example in the following example b is local to the expression. Note that if a local variable has the same name as a global variable, the value of the global variale will not be modified.
a=2;
int b=2*a;
return b
Type declarations for local variables are:
-
int
-
float
-
bool
(can also be typed boolean
)
-
string
-
int[]
-
float[]
-
bool[]
(can also be typed boolean[]
)
-
string[]
-
var
for variables which have a dynamic type
Keywords
If−then−else
If−then−else expressions are supported. For example:
if (c) {return 2} else {return 3};
or
if (!c) {return 2}
else if (b == 2) {return b * 10}
else {return 3}
If−then−else expressions can also be used inside other expresiosn or code blocks. For example:
if (!c) {return 2}
else if (b == 2) {
if (d == 3) { return 25}
else {return 45}
} else {return 3};
While loops
While loops are supported. For example:
int c = 0;
int d = 0;
while (c < 10) {
d = d + a;
c = c + 1};
Break
It is possible to add a break inside a while loop. For example:
int c = 0;
while (c < 10) {
c = c + 1;
if (c == 3) {
break;
}
};
return c;
Echo
The "echo" function prints the argument in the console. For example: "echo("a = " + a) will show the value of a in the console.
The "format" function format a value and return the String result, as in C. For example:
format(a,"%4.2f");
It is possible to add comments on a line in expressions. For example:
if (!c) {return 2}
/* first if */
else if (b == 2) {
if (d == 3) { return 25}
else {return 45}
} else {return 3};
Functions list
Function |
Syntax |
Definition |
abs |
abs(a) |
Absolute value |
sin |
sin(a) |
Sinus (input in radians) |
cos |
cos(a) |
Cosinus (input in radians) |
tan |
tan(a) |
Tangent (input in radians) |
asin |
asin(a) |
Arc sinus |
acos |
acos(a) |
Arc cosinus |
atan |
atan(a) |
Arc tangent |
atn2 |
atn2(a) |
Arc tangent 2 |
pow |
pow(a, b) |
a power b (for example pow(a, 2) is a * a) |
sqrt |
sqrt(a) |
Square root |
PI |
PI |
The PI constant |
toDegrees |
toDegrees(a) |
Conversion from radians to degrees |
toRadians |
toRadians(a) |
Conversion from degrees to radians |
echo |
echo(a) |
Echo a message in the console |
format |
format(a, pattern) |
Format a value and return the result |
Categories:
general