This page is for an old version of Hexaly Optimizer. We recommend that you update your version and read the documentation for the latest stable release.

Appendix

BNF Syntax

This is the full grammar of the LSP language. For sake of simplicity, operator priorities do not figure in this document as well as the techniques used to solve the remaining ambiguities (dandling else, ...).

function_call
    : primary_expression '(' ')'
    | primary_expression '(' func_arg_list ')'
    | primary_expression for_compositor '(' func_arg_list ')'
    ;

func_arg_list
    : expression
    | func_arg_list ',' expression

table_expression
    : '{' '}'
    | '{' table_list '}'
    ;

table_list
    : expression
    | table_key '=' expression
    | table_key ':' expression
    | table_list ',' expression
    | table_list ',' table_key '=' expression
    | table_list ',' table_key ':' expression
    ;

table_key
    : string
    | identifier
    | integer
    | '-' integer
    ;

primary_expression
    : identifier
    | 'true'
    | 'false'
    | 'nan'
    | 'inf'
    | 'nil'
    | string
    | integer
    | double
    | primary_expression '[' expression ']'
    | primary_expression '.' identifier
    | function_call
    | '(' expression ')'
    | 'this'
    ;

arithm_expression
    : primary_expression
    | lambda_expression
    | arithm_expression '||' arithm_expression
    | arithm_expression '&&' arithm_expression
    | arithm_expression '==' arithm_expression
    | arithm_expression '!=' arithm_expression
    | arithm_expression 'is' arithm_expression
    | arithm_expression 'is' 'nil'
    | arithm_expression 'is' 'int'
    | arithm_expression 'is' 'double'
    | arithm_expression '<' arithm_expression
    | arithm_expression '>' arithm_expression
    | arithm_expression '<=' arithm_expression
    | arithm_expression '>=' arithm_expression
    | arithm_expression '+' arithm_expression
    | arithm_expression '-' arithm_expression
    | arithm_expression '*' arithm_expression
    | arithm_expression '/' arithm_expression
    | arithm_expression '%' arithm_expression
    | arithm_expression '?' arithm_expression ':' arithm_expression
    | '+' arithm_expression
    | '-' arithm_expression
    | '!' arithm_expression
    | 'typeof' arithm_expression
    ;

lambda_expression
    : identifier '=>' block_statement
    | '(' func_identifier_list ')' '=>' block_statement
    | '(' ')' '=>' block_statement
    |  identifier '=>' arithm_expression
    | '(' func_identifier_list ')' '=>' arithm_expression
    | '(' ')' '=>' arithm_expression
    | 'function' '(' func_identifier_list ')' block_statement
    | 'function' '(' ')' block_statement
    ;

expression
    : arithm_expression
    | table_expression
    ;

for_compositor
    : '[' filter_iterator ']'
    | for_compositor '[' filter_iterator ']'
    ;

filter_iterator
    : identifier 'in' expression ':' expression
    | identifier ',' identifier 'in' expression ':' expression
    | identifier 'in' expression '..' expression ':' expression
    | identifier 'in' expression
    | identifier ',' identifier 'in' expression
    | identifier 'in' expression '..' expression
    | expression '..' expression
    ;

modifier
    : 'minimize'
    | 'maximize'
    | 'constraint'
    ;

modifier_statement
    : modifier expression ';'
    ;

assignment_operator
    : '='
    | '<-'
    | '+='
    | '-='
    | '/='
    | '*='
    | '%='
    ;

local_assignment_operator
    : '='
    | '<-'
    ;

assignment_statement
    : identifier assignment_operator expression ';'
    | identifier assg_compositor assignment_operator expression ';'
    ;

local_assignment_statement
    : 'local' identifier local_assignment_operator expression ';'
    | 'local' identifier assg_compositor local_assignment_operator expression ';'
    ;

assg_compositor
    : '[' filter_iterator ']'
    | '[' expression ']'
    | '.' identifier
    | assg_compositor '[' filter_iterator ']'
    | assg_compositor '[' expression ']'
    | assg_compositor '.' identifier
    ;

local_statement
    : 'local' identifier ';'
    ;

if_condition
    : 'if' '(' expression ')'
    ;

if_else_statement
    : if_condition statement
    | if_condition statement 'else' statement
    ;

for_statement
    : 'for' for_compositor statement
    ;

while_statement
    : 'while' '(' expression ')' statement
    ;

dowhile_statement
    : 'do' statement 'while' '(' expression ')' ';'
    ;

statement_list
    : statement
    | statement_list statement
    ;

block_statement
    : '{' '}'
    | '{' statement_list '}'
    ;

function_call_statement
    : function_call ';'
    ;

return_statement
    : 'return' ';'
    | 'return' expression ';'
    ;

continue_statement
    : 'continue' ';'
    ;

break_statement
    : 'break' ';'
    ;

throw_statement
    : 'throw' expression ';'
    | 'throw' ';'
    ;


trycatch_statement
    : 'try' statement 'catch' '(' identifier ')' statement
    ;

statement
    : block_statement
    | assignment_statement
    | local_assignment_statement
    | local_statement
    | if_else_statement
    | for_statement
    | while_statement
    | dowhile_statement
    | continue_statement
    | break_statement
    | modifier_statement
    | function_call_statement
    | return_statement
    | throw_statement
    | trycatch_statement
    | ';'
    ;

func_identifier_list
    : identifier
    | func_identifier_list ',' identifier
    ;

function
    : 'function' identifier '(' func_identifier_list ')' block_statement
    | 'function' identifier '(' ')' block_statement
    ;

function_list
    : function
    | function_list function

use_section
    : use_statement
    | use_section use_statement

use_statement
    : 'use' identifier ';'

start
    : <EOF>
    | function_list <EOF>
    | use_section <EOF>
    | use_section function_list <EOF>
    ;