Language Reference - Textual Language - Actions


The action language syntax is defined by the following abstract grammar:


actions ::= (action ';')*

action ::=   (('S' | 'P' | 'X', 'A') stmt)
           | ('N' expr8) // expr8 must reference a digital output or a boolean variable

stmt ::=   assignment
         | callStmt

assignment ::= expr8 '=' expr // expr8 may not reference an input or constant variable

callStmt ::= expr8 // must be a call expression

expr  ::= expr1 ('?' expr ':' expr)? // conditional expression
expr1 ::= expr2 ('&' expr2)* // boolean and
expr2 ::= expr3 ('|' expr3)* // boolean or
expr3 ::= expr4 (('==' | '!=') expr4)* // equality, non-equality
// numerical operations: less than, greater than, less than or equal, greater than or equal
expr4 ::= expr5 (('<' | '>' | '<=' | '>=') expr5)*
expr5 ::= expr6 (('+' | '-') expr6)* // addition or string concatenation, subtraction
expr6 ::= expr7 (('*' | '/' | '%') expr7)* // multiplication, division, modulo (a % b = a - int(a / b)*b)
expr7 ::= ('-' | '!') expr7 | expr8 // numerical negation, boolean negation
expr8 ::= expr9 ('.' expr9)*
expr9 ::=   string
          | number
          | function
          | idRefs
          | '(' expr ')'
          
// Ordinary strings with support for escape sequences.
string ::= '"' (~['"','\\','\n','\r'] | '\\' (
                 ['n','t','b','r','f','\\','\'','"'] |
                 ['0'-'7'] (['0'-'7'])? | ['0'-'3'] ['0'-'7'] ['0'-'7'])
               )* '"'

number ::= (digit)+ ('.' (digit)+)?

function ::= id '(' (argumentList)? ')'

argumentList ::= expr (',' expr)*

idRefs ::= id ('^')*

id = (letter)+ (digit | letter)*

digit = ['0'-'9']

letter = ['a'-'z' | 'A'-'Z' | '_']

where

C++-style line comments are also supported, e.g.
S var = 42; // The answer to life the universe and everything

Comments: