Home
Categories
Dictionnary
Download
Project Details
Changes Log

Grammar


    1  Overview
    2  Syntax
       2.1  Expressions types
       2.2  Affectations
       2.3  Post−increment operator
       2.4  Smart−assembler operator
       2.5  Code blocks
       2.6  Local variables
    3  Keywords
       3.1  If−then−else
       3.2  While loops
       3.3  Break
       3.4  Echo
       3.5  Format
       3.6  Comments
    4  Functions list

This article presents the supported grammar and syntax of the expressions.

Overview

All classic numeric and boolean functions are supported: Additionally:

Syntax

Expressions types

Expresions use the following syntax:

Affectations

It is possible to use affectations in expressions. For example, for the expression "b=2*a":

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 "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:

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.

Format

The "format" function format a value and return the String result, as in C. For example:

      format(a,"%4.2f");  

Comments

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

Copyright 2018 Herve Girod. All Rights Reserved