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.
expression
: ternary_expression
| lambda_expression
| table_expression
;
ternary_expression
: or_expression
| or_expression '?' ternary_expression ':' ternary_expression
;
or_expression
: and_expression
| or_expression '||' and_expression
;
and_expression
: equality_expression
| and_expression '&&' equality_expression
;
equality_expression
: relational_expression
| equality_expression '==' relational_expression
| equality_expression '!=' relational_expression
;
relational_expression
: range_expression
| relational_expression 'is' range_expression
| relational_expression 'is' 'nil'
| relational_expression 'is' 'bool'
| relational_expression 'is' 'int'
| relational_expression 'is' 'double'
| relational_expression '<' range_expression
| relational_expression '>' range_expression
| relational_expression '<=' range_expression
| relational_expression '>=' range_expression
;
range_expression
: additive_expression
| additive_expression '..' additive_expression
| additive_expression '...' additive_expression
;
additive_expression
: multiplicative_expression
| additive_expression '+' multiplicative_expression
| additive_expression '-' multiplicative_expression
;
multiplicative_expression
: unary_expression
| multiplicative_expression '*' unary_expression
| multiplicative_expression '/' unary_expression
| multiplicative_expression '%' unary_expression
;
unary_expression
: primary_expression
| '+' unary_expression
| '-' unary_expression
| '!' unary_expression
| 'typeof' unary_expression
;
primary_expression
: identifier
| 'true'
| 'false'
| 'nan'
| 'inf'
| 'nil'
| string
| integer
| double
| primary_expression '[' expression ']'
| primary_expression '.' identifier
| function_call
| '(' expression ')'
;
lambda_expression
: identifier '=>' block_statement
| '(' function_identifier_list ')' '=>' block_statement
| '(' ')' '=>' block_statement
| identifier '=>' lambda_body_expression
| '(' function_identifier_list ')' '=>' lambda_body_expression
| '(' ')' '=>' lambda_body_expression
| 'function' '(' function_identifier_list ')' block_statement
| 'function' '(' ')' block_statement
;
lambda_body_expression
: ternary_expression
| lambda_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
;
function_call
: primary_expression '(' ')'
| primary_expression '(' function_argument_list ')'
| primary_expression variadic_compositor_list '(' function_variadic_list ')'
;
function_argument_list
: expression
| function_argument_list ',' expression
;
function_variadic_list
: expression
| function_variadic_list ',' expression
;
variadic_compositor_list
: '[' filter_iterator ']'
| variadic_compositor_list '[' filter_iterator ']'
;
filter_iterator
: identifier 'in' expression ':' expression
| identifier ',' identifier 'in' expression ':' expression
| identifier 'in' expression
| identifier ',' identifier 'in' expression
;
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
| throw_statement
| trycatch_statement
| with_statement
| function_call_statement
| return_statement
| ';'
;
block_statement
: '{' '}'
| '{' statement_list '}'
;
statement_list
: statement
| statement_list statement
;
assignment_statement
: identifier assignment_operator expression ';'
| identifier assignment_compositor_list assignment_operator expression ';'
;
assignment_operator
: '='
| '<-'
| '+='
| '-='
| '/='
| '*='
| '%='
;
assignment_compositor_list
: assignment_compositor
| assignment_compositor_list assignment_compositor
;
assignment_compositor
: '[' filter_iterator ']'
| '[' expression ']'
| '.' identifier
;
local_assignment_statement
: 'local' identifier local_assignment_operator expression ';'
| 'local' identifier assignment_compositor_list local_assignment_operator expression ';'
;
local_assignment_operator
: '='
| '<-'
;
local_statement
: 'local' identifier ';'
;
if_else_statement
: if_condition statement
| if_condition statement 'else' statement
;
if_condition
: 'if' '(' expression ')'
;
for_statement
: 'for' for_compositor_list statement
;
for_compositor_list
: '[' filter_iterator ']'
| for_compositor_list '[' filter_iterator ']'
;
while_statement
: 'while' '(' expression ')' statement
;
dowhile_statement
: 'do' statement 'while' '(' expression ')' ';'
;
continue_statement
: 'continue' ';'
;
break_statement
: 'break' ';'
;
modifier_statement
: modifier expression ';'
;
modifier
: 'minimize'
| 'maximize'
| 'constraint'
;
throw_statement
: 'throw' expression ';'
| 'throw' ';'
;
trycatch_statement
: 'try' statement 'catch' '(' identifier ')' statement
;
with_statement
: 'with' '(' with_resource ')' statement
;
with_resource
: identifier
| identifier '=' expression
function_call_statement
: function_call ';'
;
return_statement
: 'return' ';'
| 'return' expression ';'
;
function_list
: function
| function_list function
;
function
: 'function' identifier '(' function_identifier_list ')' block_statement
| 'function' identifier '(' ')' block_statement
;
function_identifier_list
: identifier
| function_identifier_list ',' identifier
;
pragma_list
: pragma_statement
| pragma_list pragma_statement
;
pragma_statement
: 'pragma' identifier ';'
| 'pragma' identifier identifier ';'
| 'pragma' identifier integer ';'
| 'pragma' identifier double ';'
;
use_list
: use_statement
| use_list use_statement
;
use_statement
: 'use' identifier ';'
;
header_section
: pragma_list
| pragma_list use_list
| use_list
;
program
: <EOF>
| function_list <EOF>
| header_section <EOF>
| header_section function_list <EOF>
;