compilation_unit : 'модуль' ident import* declaration* ; import : 'импорт' (ident '=')? import_path ; import_path : string ; declaration : type_decl | const_decl | var_decl | func_decl | entry ; //==== types type_decl : 'тип' name '=' type_def ; name : ident '*'? // export mark ; type_def : array_def | class_def //? | func_type ; array_def : '[' ']' type_ref // single dimension ; class_def : 'класс' base_type? '{' class_fields* '}' ; base_type : '(' type_ref ')' ; class_field : name ':' type_ref ; type_ref : qualident '?'? ; qualident : ident ('.' ident) ; //==== consts and vars const_decl : 'конст' (single_const | group_const) ; single_const : name (':' type_ref)? '=' const_expression ; group_const : '(' single_const (separator name)* ')' ; const_expression // to be extended later : literal | qualident ; var_decl : 'пусть' name ':' type_ref ('=' expression) // 'дано' for let //=== function func_decl : 'фн' receiver? name signature statement_seq? ; receiver : '(' ident ':' type_ref ')' ; signature : '(' param_list? ')' result_type? ; param_list : param (',' param)* ','? ; param : ident ':' type_ref ; result_type : ':' type_ref ; //=== entry entry : 'вход' statement_seq ; //=== statements statement_seq : '{' statement_or_decl* '}' ; statement_or_decl : statement | const_decl | var_decl ; statement : if_stm | while_stm //| switch_stm | 'прервать' | 'вернуть' expression? | assignment | expression ('++' | '--')? ; if_stm : 'если' expression statement_seq ('иначе' statement_seq)? ; while_stm : 'пока' expression statement_seq ; //switch_stm // : 'выбор' // TBD // ; assignment : expression ':=' expression ; //==== expression expression : unary_expr | expression binary_op expression ; unary_expr : primary_expr | unary_op unary_expr ; binary_op: '|' | '&' | rel_op | add_op | mul_op; rel_op: '=' | '#' | '<' | '<=' | '>' | '>='; add_op: '+' | '-' | '|.' | 'xor'; mul_op: '*' | '/' | '%' | '&.'; unary_op: '+' | '-' | '~'; // '~' for not // TODO: bitnot ? '^' // TODO: shifts << >> primary_exp : operand | primary_expr selector | primary_expr arguments | primary_expr conversion | primary_expr index_or_array_composite | primary_expr class_composite // no space allowed ; operand : literal | qualident | '(' expression ')' // | lambda // later ; literal : INTEGER | FLOAT | STR ; selector: '.' ident; arguments: '(' expression_list? ')' conversion: '-' type_ref '¬'; // like х-вещ64¬ expression_list : expression (',' expression)* ','? // trailing comma allowed ; index_or_array_composite : '[' expression ']'; | array_composite ; array_composite : '[' element_value_list? ']' ; element_value_list : element_value (',' element_value)* ','? // trailing comma allowed ; element_value : expression (':' expression) class_composite : '{' field_value_list? '}' ; field_value_list : field_value (',' field_value)* ','? // trailing comma allowed ; field_value : ident ':' expression ; //=== TBD: ident and all other lexer