compilation_unit : module_cu | definition_cu ; module_cu : 'модуль' ident import* declaration* ; definition_cu : 'определения' ident import* declaration* ; import : 'импорт' (ident '=')? import_path ; import_path : string ; declaration : type_decl | const_decl | var_decl | func_decl | init ; //==== 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)? '=' literal // to be extended later ; group_const : '(' single_const (separator name)* ')' ; var_decl : 'пер' name ':' type_ref ('=' expression) // another keyword? ; //=== 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 ; //=== init init : 'вход' statement_seq ; //=== statements statement_seq : '{' statement_or_decl* '}' ; statement_or_decl : statement | const_decl | var_decl ; statement : if_stm | while_stm | switch_stm | 'break' | 'return' | assignment | expression ('++' | '--')? ; if_stm : 'если' expression statement_seq ('иначе' statement_seq)? ; while_stm : 'пока' expression statement_seq ; switch_stm : 'выбор' // TBD ; assignment : expression ':=' expression ; //==== expression //TBD