/* number : NUM_INT ; real_number : NUM_REAL ; identifier : IDENT ; string_literal : STRING_LITERAL ; */ label_ident : id: identifier | num: number; qualified_name : id:identifier ( cont_name )* ; cont_name : '.' id:identifier ; ifc_type : simple_alias_type ; param_type : simple_alias_type | simple_string_type ; simple_alias_type : qual_name:qualified_name ; simple_string_type : "string" ; simple_file_type : "file" ; /* ---------------------------------------------------------------------- */ index_expr_item : ref:expr ; index_expr_list : index_expr_item ( ',' index_expr_item )* ; /* arguments */ arg_item : value:expr ( ':' width:expr ( ':' digits:expr )? )? ; arg_list : arg_item ( ',' arg_item )* ; /* set constructor */ elem_sect : elem_item ( ',' elem_item )* ; elem_item : low:expr ( ".." high:expr )? ; /* structure constructor */ struct_item : ( name:identifier ':' )? value:expr ; struct_sect : struct_item ( ',' struct_item ( ',' struct_item )* | ';' struct_item ( ';' struct_item )* )? ; /* factor */ ident_expr : ident:identifier ; int_value_expr : value:number ; float_value_expr : value:real_number ; string_value_expr : value:string_literal ; nil_expr : "nil" ; sub_expr : '(' value:expr ')' ; not_expr : "not" param:factor ; plus_expr : '+' param:factor ; minus_expr : '-' param:factor ; adr_expr : '@' param:factor ; set_expr : '[' list:elem_sect ']' ; super_expr : "inherited" ident:identifier ; string_type_expr : "string" "(" param:expr ")" ; variable : int_value_expr | float_value_expr | string_value_expr | not_expr | plus_expr | minus_expr | adr_expr | nil_expr | set_expr | // ( "string" '(' ) => string_type_expr | // !? reference ; /* term */ term : left:factor ( ('*' | '/' | "div" | "mod" | "shl" | "shr" | "and" | "as" ) right:term )? ; /* simple expression */ simple_expr : left:term ( ( '+' | '-' | "or" | "xor" ) right:simple_expr )? ; /* expression */ expr : left:simple_expr ( ('=' | "<>" | '<' | '>' | "<=" | ">=" | "in" | "is" ) right:simple_expr )? ; /* ---------------------------------------------------------------------- */ /* goto */ goto_stat : "goto" goto_lab:label_ident ; /* begin end */ begin_stat : "begin" body_seq:stat_list "end" ; stat_list : stat ( ';' stat )* ; /* if */ if_stat : "if" cond_expr:expr "then" then_stat:stat ( "else" else_stat:stat )? ; /* case */ case_stat : "case" case_expr:expr "of" case_list:case_sect ( "else" else_seq:stat_list )? "end" ; case_sect : case_item ( ';' case_item )*; case_item : sel_list:elem_sect ':' sel_stat:stat ; /* while */ while_stat : "while" cond_expr:expr "do" body_stat:stat ; /* repeat */ repeat_stat : "repeat" body_seq:stat_list "until" until_expr:expr ; /* for */ for_stat : "for" var_expr:variable ":=" from_expr:expr ( "to" | "downto" ) to_expr:expr "do" body_stat:stat ; /* with */ with_stat : "with" with_list:with_sect "do" body_stat:stat ; with_sect : with_item ( ',' with_item )* ; with_item : expr:variable ; /* raise */ raise_stat : "raise" ( raise_expr:expr )? ; /* try */ try_stat : "try" body_seq:stat_list ( finally_branch:finally_part | except_branch:except_part ) "end" ; finally_part : "finally" finally_seq:stat_list ; except_part : "except" ( on_list:on_sect ( "else" else_seq:stat_list )? | else_seq:stat_list ); on_sect : on_item ( ';' on_item )* ( ';' )? ; on_item : "on" ( on_ident:identifier ':' )? on_type:type "do" body_stat:stat ; /* empty statement */ empty_stat : ; /* simple statement */ simple_stat : expr ( assign_stat | call_stat ) ; assign_stat : ":=" right_expr:expr ; call_stat : ; /* labeled statement */ labeled_stat : lab:label_ident ':' body:stat ; /* statement */ stat : field_decl | method_decl | property_decl ; /* field */ field_ident : name:identifier ; field_decl : field_ident ( ',' field_ident )* ':' typ:type; /* method */ method_decl : proc_head ( "virtual" | "dynamic" | "message" a_message:expr | "override" | "abstract" )* ; /* property */ property_decl : "property" name:identifier ( param_list:property_param_list )? ( ':' typ:result_type )? ( "index" index:expr )? ( "read" a_read:expr )? ( "write" a_write:expr )? ( "stored" )? ( "default" )? ( "nodefault" )? ( "implements" a_implements:interface_sect )? ( ';' "default" ';' )? ';' ; /* ---------------------------------------------------------------------- */ /* enum */ enum_type : '(' elements:enum_sect ')' ; enum_sect : enum_item ( ',' enum_item )* ; enum_item : name:identifier ; /* string */ string_type : "string" ( '[' lim:expr ']' )? ; /* array */ array_type : "array" ( '[' index_list:index_type_sect ']' )? "of" elem:type; index_type_sect : index_type_item ( ',' index_type_item )* ; index_type_item : index:type ; /* record */ record_type : "record" fields:field_sect "end" ; field_sect : ( field_decl )* ; /* pointer */ pointer_type : '^' elem:type; /* set */ set_type : "set" "of" elem:type; /* file */ file_type : "file" ( "of" elem:type )? ; /* class of type */ class_of_type : "class" "of" elem:type ; /* procedure */ proc_type : ( "procedure" | "function" ) param_list:formal_param_list ( ':' answer:result_type )? ( "of" "object" )? ( "register" | "pascal" | "cdecl" | "stdcall" | "safecall" )? ; /* other type */ range_type : low:simple_expr ".." high:simple_expr ; alias_type : qual_name:qualified_name ; /* type */ type : const_sect | type_sect | var_sect | proc_intf_decl ; intf_decl_part : ( intf_decl )* ; decl : unit_decl | program_decl | library_decl ;