Appendices

Grammar definition

//_______________________________________________
// relaxed simple ITL format specification
//_______________________________________________
start        : expr
            | start expr
            ;
//_______________________________________________
// expression of the script language
//_______________________________________________
expr        : message  ENDEXPR        
            | variabledecl ENDEXPR    
            | script            
            | ENDSCRIPT            
            ;
//_______________________________________________
// javascript and support
//_______________________________________________
script        : JSCRIPT            
            ;
//_______________________________________________
// messages specification (extends osc spec.)
//_______________________________________________
message        : address                    
            | address params            
            | address eval LEFTPAR messagelist RIGHTPAR
            | address eval variable        
            ;
messagelist : message                    
            | messagelist messagelistseparator message 
            ;
messagelistseparator    : COMMA
                        | COLON
                        ;
//_______________________________________________
// address specification (extends osc spec.)
address        : oscaddress                
            | relativeaddress            
            | urlprefix oscaddress        
            ;
oscaddress  : OSCADDRESS                
            ;
relativeaddress    : POINT oscaddress        
            ;
urlprefix    : hostname  UINT            
            | STRING COLON UINT            
            | IPNUM COLON UINT            
            ;
hostname    : HOSTNAME                    
            ;
identifier    : IDENTIFIER                
            | HOSTNAME                    
            | REGEXP                    
            ;
//_______________________________________________
// parameters definitions
// eval need a special case since messages are expected as argument
eval        : EVAL                
            | variable                
            | params variable        
            | params param            
            ;
params        : sparam                
            | params sparam            
            | mathexpr                
            | params mathexpr        
            ;
variable    : VARIABLE                
            | VARIABLEPOSTINC        
            | VARIABLEPOSTDEC        
            | VARIABLEPREINC        
            | VARIABLEPREDEC        
            ;
msgvariable    : VARSTART LEFTPAR message RIGHTPAR 
            ;
param    : number                
        | FLOAT                    
        | identifier            
        | STRING                
        ;
sparam    : expression            
        | LEFTPAR messagelist RIGHTPAR    
        | script            
        ;
//_______________________________________________
// math expressions
mathexpr    : param                            
            | variable                        
            | msgvariable                    
            | mathexpr ADD mathexpr            
            | mathexpr SUB mathexpr            
            | MINUS mathexpr                
            | mathexpr MULT mathexpr        
            | mathexpr DIV mathexpr            
            | mathexpr MODULO mathexpr        
            | LEFTPAR mathexpr RIGHTPAR     
            | MIN LEFTPAR mathmin RIGHTPAR    
            | MAX LEFTPAR mathmax RIGHTPAR    
            | LEFTPAR mathbool QUEST mathexpr COLON mathexpr RIGHTPAR 
            ;
mathmin     : mathexpr                        
            | mathmin mathexpr                
            ;
mathmax     : mathexpr                        
            | mathmax mathexpr                
            ;
mathbool     : mathexpr                        
            | NEG mathexpr                    
            | mathexpr EQ mathexpr             
            | mathexpr NEQ mathexpr         
            | mathexpr GREATER mathexpr     
            | mathexpr GREATEREQ mathexpr     
            | mathexpr LESS mathexpr         
            | mathexpr LESSEQ mathexpr         
            ;
//_______________________________________________
// variable declaration
variabledecl : varname EQUAL params    
            ;
varname        : IDENTIFIER            
            ;
//_______________________________________________
// misc
number        : UINT                    
            | INT                    
            ;
//_______________________________________________
// expression declaration
expression    : EXPRESSION    
            ;

Lexical tokens

//_______________________________________________
// numbers
//_______________________________________________
INT       a signed integer
UINT      an unsigned integer
FLOAT     a floating point number

//_______________________________________________
// hosts addresses
//_______________________________________________
// allowed character set for host names (see RFC952 and RFC1123)
HOSTNAME       : [-a-zA-Z0-9]+ 
IPNUM          :  {DIGIT}+"."{DIGIT}+"."{DIGIT}+"."{DIGIT}+

//_______________________________________________
// OSC addresses
//_______________________________________________
// allowed characters for identifiers
IDENTIFIER     : [_a-zA-Z][_a-zA-Z0-9]*
REGEXP           see OSC doc for regular expressions
OSCADDRESS

//_______________________________________________
// strings
//_______________________________________________
STRING          : ("/"|(".""."?"/")*)([^ \t/?:*><|"';=]+"/"?)+"."[_a-zA-Z0-9]+
                  or quoted strings that can include any character
                  quotes could be single (') or double quotes (")

//_______________________________________________
// scripting
//_______________________________________________
JSCRIPT        : <?javascript any javascript code ?>
VARIABLE       : the name of a name

//_______________________________________________
// misc.
//_______________________________________________
POINT          : '.'
VARSTART       : '$'
COLON          : ':'
COMMA          : ','
LEFTPAR        : '('
RIGHTPAR       : ')'
EQUAL          : '='
ENDEXPR        : ';'
ENDSCRIPT      : "__END__"
EVAL           : "eval"

//_______________________________________________
// score expressions
//_______________________________________________
EXPRESSION    expr( a valid score expression )
              see 'Score expressions grammar'

//_______________________________________________
// math expressions
//_______________________________________________
ADD            : '+'
DIV            : '/'
EQ             : '=='
GREATER        : '>'
GREATEREQ      : '>='
LESS           : '<'
LESSEQ         : '<='
MINUS          : '-'
MODULO         : '
MULT           : '*'
NEG            : '!'
QUEST          : ' ? '
SUB            : '- '
MAX            : '@max' 
MIN            : '@min'

VARIABLEPOSTDEC : $VAR--
VARIABLEPOSTINC : $VAR++
VARIABLEPREDEC  : --$VAR
VARIABLEPREINC  : ++$VAR

Score expressions grammar

//_______________________________________________
// relaxed simple IExpression format specification
//_______________________________________________
start        : expression            
            ;
//_______________________________________________
//misc
identifier    : IDENTIFIER            
            ;
string        : identifier
            | STRING                
            | QUOTEDSTRING            
            ;
variable    : VARSTART identifier    
            ;
//_______________________________________________
// expression declaration
expression    : EXPR_START operator exprArg exprArg EXPR_END    
            | EXPR_START exprArg EXPR_END                    
            | EXPR_START operator variable EXPR_END            
//            | EXPR_START variable exprArg EXPR_END            
            ;
operator    : identifier
            | variable    
            ;
exprArg        : arg
            | AMPERSAND arg    
            | TILDE arg    
            | expression
            ;
arg            : string    
            | variable    
            ;