/* ckit/cmm.g */ options { /* output file names */ common_header = cmm_data; // common header (.hpp) (enumerations, class names) common_name = cmm_data; // common code (.cpp) // public_header = cmm_public; // public header (.hpp) (classes) // private_header = cmm_private; // private header (.hpp) (private classes) // symbol_header = cmm_symbol; // symbol type header (.hpp) (enumeration) lexer_name = cmm_lexer; // output file name prefix (.gpp, .hpp, .cpp) parser_name = cmm_parser; // output file name prefix (.gpp, .hpp, .cpp) product_name = cmm_product; // output file name prefix (.hpp, .cpp) /* iput file names */ // product_input = "ext.h"; // input include file with additional product declarations /* classes and namespaces */ // product_namespace = finch; automatic_namespace = true; lexer_class = CmmLexer; lexer_super_class = TLexerInput; parser_class = CmmParser; // parser_super_class = TEnvInput; product_class = CmmProduct; product_super_class = CmmOutput; /* options */ // switchable_literals = true; // tree_code = true; // open_method = true; // open_parser and close_parser methods // notes = true; // store comments and spaces // only_start_notes = true; // fixed_notes = true; // true .. variables, not array locations = true; // store line numbers // ignore_locations = true; // ignore_notes = true; // note_type = CmmNote; location_type = CmmLocation; mark_type = CmmMark; // note_init = "\"\""; location_init = "NULL"; // initialization value for locations // anonymous_fields = true; ignore_send_options = true; // no custom send, ... // ignore_output_options = true; // no custom output, internal_output // ignore_execute_options = true; // no execute methods // ignore_product_constructor = true; // only for gram initialize_variables = true; // antlr_mode = true; // lexer_input = "lex.g"; // product_namespace = finch; symbol_type = CmmSymbol; no_symbol = NONE; keyword_prefix = LITERAL_ ; // subst_type = CmmDefineItem; // replace_type = CmmEntry; /* identifiers */ /* rule_prefix = rule_ ; type_prefix = type_ ; field_prefix = field_ ; list_prefix = queue_ ; internal_prefix = internal_ ; send_func_prefix = send_fce_ ; send_internal_prefix = original_ ; open_func_prefix = open_fce_ ; close_func_prefix = close_fce_ ; conv_func_prefix = convert_ ; util_func_prefix = utility_ ; param_prefix = parameter_ ; temp_prefix = temporary_ ; local_prefix = local_ ; variable_prefix = variable_ ; literal_prefix = literal_ ; */ /* symbol_type = enum_CmmSymbol; no_symbol = no_symbol; primitive_prefix = simple_ ; delimiter_prefix = delimiter_ ; keyword_prefix = keyword_ ; */ basic_type = CmmBasic; expr_type = CmmExpr; binary_expr_type = CmmBinaryExpr; binary_expr_left = left; binary_expr_right = right; binary_expr_selector = kind; unary_expr_type = CmmUnaryExpr; unary_expr_param = param; unary_expr_selector = kind; } /* --------------------------------------------------------------------- */ /* extension of cmm_data.hpp */ extension common_include {@@ @@} extension common_header {@@ class TInputItem; typedef TInputItem * CmmMark; typedef TInputItem * CmmLocation; class CttItem; class CttFunctionParams; class CttTemplateParams; class CttEval; @@} extension common_tail {@@ @@} /* extension of CmmBasic class */ extension common_class {@@ @@} /* --------------------------------------------------------------------- */ extension lexer_include {@@ #include "input.h" #include "ioexception.h" @@} extension lexer_header {@@ @@} extension lexer_class {@@ public: virtual void translate (); void close_parser (); @@} /* --------------------------------------------------------------------- */ /* extension of cmm_parser.h and CmmParser class */ extension parser_include {@@ @@} extension parser_header {@@ @@} extension parser_class {@@ public: bool examine_type_name (CmmName * name); bool examine_type_or_declaration (bool decl, bool parenthesis, bool common); @@} /* --------------------------------------------------------------------- */ /* extension of cmm_product.h and CmmProduct class */ extension product_include {@@ #include "output.h" @@} extension product_header {@@ @@} extension product_class {@@ @@} /* --------------------------------------------------------------------- */ literals // identifiers for C++ literals { LPAREN : '(' ; RPAREN : ')' ; LBRACKET : '[' ; RBRACKET : ']' ; LBRACE : '{' ; RBRACE : '}' ; DOT : '.' ; ARROW : "->" ; SCOPE : "::" ; LOG_NOT : '!' ; BIT_NOT : '~' ; INC : "++" ; DEC : "--" ; DOT_STAR : ".*" ; ARROW_STAR : "->*" ; STAR : '*' ; SLASH : '/' ; MOD : '%' ; PLUS : '+' ; MINUS : '-' ; SHL : "<<" ; SHR : ">>" ; LESS : '<' ; GREATER : '>' ; LESS_OR_EQUAL : "<=" ; GREATER_OR_EQUAL : ">=" ; EQUAL : "==" ; UNEQUAL : "!=" ; BIT_AND : '&' ; BIT_XOR : '^' ; BIT_OR : '|' ; LOG_AND : "&&" ; LOG_OR : "||" ; ASSIGN : '=' ; MUL_ASSIGN : "*=" ; DIV_ASSIGN : "/=" ; MOD_ASSIGN : "%=" ; PLUS_ASSIGN : "+=" ; MINUS_ASSIGN : "-=" ; SHL_ASSIGN : "<<=" ; SHR_ASSIGN : ">>=" ; BIT_AND_ASSIGN : "&=" ; BIT_XOR_ASSIGN : "^=" ; BIT_OR_ASSIGN : "|=" ; QUESTION : '?' ; COMMA : ',' ; COLON : ':' ; SEMICOLON : ';' ; DOTS : "..." ; } /* --------------------------------------------------------------------- */ // CmmAccess type shared by CmmMemberSect and CmmBaseItem enum CmmAccess { NoAccess, // default value PrivateAccess, ProtectedAccess, PublicAccess }; struct CmmMemberVisibility { CmmAccess access; }; struct CmmBaseItem { CmmAccess access; }; // data used during declaration processig struct CmmBasic { CmmBasic * next_usage; }; struct CmmName { CttItem * name_ref; CttItem * base_ref; string replace; // anonymous types !? }; struct CmmContName { CttItem * cont_ref; }; struct CmmDeclarator { CmmDeclarator * save; // used by inner declarator // data used by declaraton processing CmmAccess access_val; bool separate_decl; // declaration outside of class CmmSimpleDecl * actual_decl; // corresponding declaration string short_name; // identifier !? CmmName * long_name; // qualified name !? CttFunctionParams * function_param_ref; // function parameters }; struct CmmFunctionSpecifier { CttFunctionParams * param_ref; }; /* --------------------------------------------------------------------- */ parser ; /* --------------------------------------------------------------------- */ identifier : IDENT ; numeric_literal : NUMBER ; char_literal : CHAR_LITERAL ; string_literal : STRING_LITERAL ; /* --------------------------------------------------------------------- */ /* compound name */ base_subst : id: identifier; base_name : ( spec: special_function | base_subst // !? last - important ); base_args : ( { is_template_arg }? // %% template_args:template_arg_list )? ; cont_item : "::" cont_name cont_args ; cont_subst : id: identifier; cont_name : ( '~' | "template" )? ( spec: special_function | cont_subst // !? last - important ); cont_args : ( { is_cont_template_arg }? // %% template_args:template_arg_list )? ; compound_name : base_name base_args ( cont_item )* ; simple_name : base_name ; global_mark : ( "::" )? ; /* --------------------------------------------------------------------- */ /* qualified name */ qualified_name : // identifer used in simple expression compound_name ; /* global name */ global_name : // namespaces, using declarations and class member initialization global_mark compound_name ; /* declaring name */ global_declaring_name : // type used in declaration specifiers global_mark compound_name ; /* type name */ global_type_name : // after typename keyword or in base class specification global_mark compound_name ; /* new name */ simple_new_name : // namespace definition, enumeration item, template type parameter simple_name ; global_new_name : // identifier in declarator, class or enumeration type global_mark compound_name ; /* --------------------------------------------------------------------- */ /* id expr */ id_expr : qualified_name; /* primary expression */ primary_expr : modern_cast_expr | typeid_expr | typename_expr // !? | type_change_expr // !? | primary_expr ; // !? last - important modern_cast_expr : ( "dynamic_cast" | "static_cast" | "const_cast" | "reinterpret_cast" ) '<' type:type_id '>' '(' param:expr ')' ; typeid_expr : "typeid" '(' ( { is_type () }? // %% param1:type_id | param2:expr ) ')' ; typename_expr : "typename" name:global_type_name '(' list:expr_list ')' ; type_change_expr : // !? ( "signed" | "unsigned" | "short" | "long" ( "long" )? | // !? @@ long long "bool" | "char" | "wchar_t" | "int" | "float" | "double" | "void" ) '(' list:expr_list ')' ; postfix_expr : postfix_start ( index_expr | call_expr | field_expr | ptr_field_expr | post_inc_expr | post_dec_expr )* ; index_expr : '[' right:expr ']' ; call_expr : '(' list:expr_list ')' ; field_expr : '.' ( '~' | "template" )? name:id_expr ; ptr_field_expr : "->" ( '~' | "template" )? name:id_expr ; post_inc_expr : "++" ; post_dec_expr : "--" ; expr_list : ( assignment_expr (',' assignment_expr)* )? ; /* unary expression */ unary_expr : { is_type_in_parenthesis () }? // %% // ( cast_formula ) => cast_formula | unary_expr ; cast_formula : '(' type:type_id ')' param:cast_expr ; /* pm expression */ pm_expr : cast_expr ".*" DotMemberExp "->*" ArrowMemverExp ; /* arithmetic and logical expressions */ multiplicative_expr : pm_expr '*' MulExp '/' DivExp '%' ModExp ; additive_expr : multiplicative_expr '+' AddExp '-' SubExp ; shift_expr : additive_expr "<<" ShlExp ">>" ShrExp ; relational_expr : shift_expr '<' LtExp '>' GtExp "<=" LeExp ">=" GeExp ; equality_expr : relational_expr "==" EqExp "!=" NeExp ; and_expr : equality_expr '&' BitAndExp ; exclusive_or_expr : and_expr '^' BitXorExp ; inclusive_or_expr : exclusive_or_expr '|' BitOrExp ; logical_and_expr : inclusive_or_expr "&&" LogAndExp ; logical_or_expr : logical_and_expr "||" LogOrExp ; /* conditional expression */ conditional_expr : logical_or_expr ( conditional_cont_expr )? ; conditional_cont_expr : '?' then_expr:expr ':' else_expr:conditional_expr ; // !? @@ // ':' else_expr:assignment_expr ; // !? @@ /* assignment expression */ assignment_expr : ( identifier ':' ) => labeled_stat | { is_declaration () }? declaration_stat | // %% expression_stat | compound_stat | case_stat | default_stat | if_stat | switch_stat | while_stat | do_stat | for_stat | break_stat | continue_stat | return_stat | goto_stat | try_stat | empty_stat ; /* inner_stat and tail_stat - statements with different output indentation */ inner_stat : stat ; tail_stat : stat ; /* list of statements */ stat_list : ( stat )* ; inner_stat_list : stat_list ; /* concrete statements */ declaration_stat : decl:block_declaration ; labeled_stat : lab:identifier ':' body:stat ; case_stat : "case" case_expr:expr ':' body:stat; default_stat : "default" ':' body:stat; expression_stat : inner_expr:expr ';'; empty_stat : ';' ; compound_stat : '{' body:inner_stat_list '}' ; condition : { is_declaration () }? // %% cond_decl:simple_declaration_content | cond_expr:expr ; for_condition : ( simple_declaration_content ';' ) => // { is_declaration () }? cond_decl:simple_declaration_content | cond_expr:expr ; if_stat : "if" '(' cond:condition ')' then_stat:inner_stat ( "else" else_stat:tail_stat )? ; switch_stat : "switch" '(' cond:condition ')' body:inner_stat ; while_stat : "while" '(' cond:condition ')' body:inner_stat ; do_stat : "do" body:inner_stat "while" '(' cond_expr:expr ')' ';' ; for_stat : "for" '(' ( from_expr:for_condition )? ';' (to_expr:expr)? ';' (cond_expr:expr)? ')' body:inner_stat ; break_stat : "break" ';'; continue_stat : "continue" ';'; return_stat : "return" (return_expr:expr)? ';'; goto_stat : "goto" goto_lab:identifier ';'; /* ---------------------------------------------------------------------- */ /* declaration */ declaration_list : ( declaration )* ; declaration : simple_declaration | empty_declaration | namespace_definition | using_declaration | asm_declaration ; /* ---------------------------------------------------------------------- */ /* simple declaration */ // !? @@ simple_declaration : // : simple_declaration_content ';' ; simple_declaration_content : spec:decl_specifiers ( init_declarator ( ',' init_declarator )* ) ; /* complex declaration */ // !? @@ complex_declaration : spec:decl_specifiers ( /* (':') => */ ':' empty_width:conditional_expr ';' // !? | ';' // !? | init_declarator ( func_body:function_body | ( ',' init_declarator )* ';' ) ) ; /* constructor head */ // !? @@ constructor_head : spec:constructor_decl_specifiers ( '~' )? constructor_head_declarator ( ':' | '{' | "try" | ';' // no empty = true ) ; constructor_head_declarator : name:global_new_name cont:constructor_head_specifier_list ; constructor_head_specifier_list : constructor_head_specifier; constructor_head_specifier : function_specifier ; /* constructor declaration */ constructor_declaration : spec:constructor_decl_specifiers ( '~' )? init_declarator ( func_body:function_body | ';' // no empty = true ) ; /* function body */ function_body : ( // ( ':' ctor_init: ctor_initializer )? statements:compound_stat | "try" ( ':' ctor_init:ctor_initializer )? statements:compound_stat handlers:handler_list ) ; /* ---------------------------------------------------------------------- */ /* elaborated type specifiers */ elaborated_enum_specifier : "enum" name:global_new_name ; // !? elaborated_class_specifier : ( "class" | "struct" | "union" ) name:global_new_name; // !? /* enum and class declarations */ class_declaration : class_specifier ';' ; enum_declaration : enum_specifier ';' ; /* ---------------------------------------------------------------------- */ /* namespace definition */ namespace_definition : "namespace" ( name:simple_new_name ( '=' value:global_name ';' | namespace_body // ) | namespace_body // ); namespace_body : // before brace, important for include(s) on lexical level '{' body:declaration_list // before brace, important for include(s) '}' ; /* using declaration */ using_declaration : "using" ( "namespace" | "typename" )? name: global_name ';' ; /* extern declaration */ linkage_specification : "extern" ( language:string_literal ( '{' decl_list:declaration_list '}' | inner_decl:declaration ) | inner_decl:declaration ) ; /* asm declaration */ asm_declaration : "asm" '(' instruction:string_literal ')' ';' ; /* empty declaration */ empty_declaration : ';' ; /* ---------------------------------------------------------------------- */ /* declaration specifiers */ decl_specifiers : simple_decl_specifiers ( basic_name:global_declaring_name | class_spec:class_specifier | enum_spec:enum_specifier | typename_spec:typename_specifier | simple_type_specifiers ) simple_decl_specifiers // !? ; type_specifiers : simple_cv_specifiers ( "register" // !? @@ root/cint/inc/C__ci.h )? ( basic_name:global_declaring_name // !? | class_spec:elaborated_class_specifier | enum_spec:elaborated_enum_specifier | typename_spec:typename_specifier | simple_type_specifiers ) simple_decl_specifiers // !? ; typename_specifier : "typename" name:global_type_name ; simple_decl_specifiers : ( "typedef" | "friend" | "inline" | "virtual" | "explicit" | "mutable" | "extern" | "static" | "auto" | "register" | "const" | "volatile" )* ; constructor_decl_specifiers : ( "inline" | "virtual" | "explicit" )* ; simple_cv_specifiers : ( "const" | "volatile" )* ; simple_type_specifiers : ( "signed" | "unsigned" | "short" | "long" ( "long" )? | // !? @@ long long "bool" | "char" | "wchar_t" | "int" | "float" | "double" | "void" )@ ; /* ---------------------------------------------------------------------- */ /* enum */ enum_specifier : "enum" ( name:global_new_name ( enum_body | // NO ) | enum_body // NO ); enum_body : '{' items:enum_list '}' ; enum_list : ( enumerator ( ',' flexible_enumerator )* )? ; enumerator : name:simple_new_name // ( '=' init:const_expr )? ; flexible_enumerator : ( name:simple_new_name // ( '=' init:const_expr )? | // // !? @@ ); /* ---------------------------------------------------------------------- */ /* type id */ type_id : /* abstract_type_id */ spec:type_specifiers decl:abstract_declarator ; common_type_id : spec:type_specifiers decl:common_declarator ; /* declarator */ declarator : ptr:ptr_specifier_list ( name:global_new_name | '(' inner:declarator ')' ) cont:cont_specifier_list ; abstract_declarator : ptr:ptr_specifier_list ( // ( '(' ) => // !? { is_inner_abstract_declarator () }? '(' inner:abstract_declarator ')' )? cont:cont_specifier_list ; common_declarator_name : name:global_new_name ; common_declarator : ptr:ptr_specifier_list ( // ( '(' ) => // !? @@ { is_inner_common_declarator () }? '(' inner:common_declarator ')' | common_declarator_name )? cont:cont_specifier_list ; /* pointer specifiers */ ptr_specifier_list : ( ptr_specifier )* ; // !? @@ ptr_specifier : '*' ptr_cv_specifier_list | '&' ptr_cv_specifier_list ; member_specifier : // !? @@ only for output area:global_name member_specifier_tail ; member_specifier_tail : "::" '*' ptr_cv_specifier_list ; ptr_cv_specifier_list : ( "const" | "volatile" )* ; /* function and array specifiers */ cont_specifier_list : ( cont_specifier )* ; cont_specifier : simple_initializer | initializer_list ; flexible_initializer_item : member_visibility | { is_constructor () }? constructor_declaration // %% | complex_declaration // !? | empty_declaration | using_declaration | template_declaration ; member_list : ( member_item )* ; /* base specification */ base_specifier_list : base_specifier ( ',' base_specifier )* ; base_specifier : ( "virtual" ( "private" | "protected" | "public" | ) | "private" ( "virtual" )? | "protected" ( "virtual" )? | "public" ( "virtual" )? | ) from:global_type_name ; /* constructor initializer */ ctor_initializer : member_initializer ( ',' member_initializer )* ; member_initializer : name:global_name '(' params:expr_list ')'; // !? global_name /* ---------------------------------------------------------------------- */ /* special member functions */ conversion_specifiers : // !? @@ type_specifiers ptr:ptr_specifier_list ; special_function : "operator" ( conv:conversion_specifiers // !? @@ | "new" ( ('[' ']') => '[' ']' )? // !? | "delete" ( ('[' ']') => '[' ']' )? | "+" | "-" | "*" | "/" | "%" | "^" | "&" | "|" | "~" | "!" | "=" | "<" | ">" | "+=" | "-=" | "*=" | "/=" | "%=" | "^=" | "&=" | "|=" | "<<" | ">>" | ">>=" | "<<=" | "==" | "!=" | "<=" | ">=" | "&&" | "||" | "++" | "--" | "," | "->*" | "->" | "(" ")" | "[" "]" ) ; /* ---------------------------------------------------------------------- */ /* template declaration */ template_declaration : common_template_declaration ; extern_template_declaration : // GNU extension "extern" common_template_declaration ; common_template_declaration : template_specification inner_decl:declaration ; template_specification : ( "export" )? "template" ( '<' ( params:template_param_list | ) '>' // !? | ); template_param_list : template_param ( ',' template_param )* ; template_param : { is_type () }? // %% template_type_arg | template_value_arg; template_type_arg : type:type_id; // !? template_value_arg : value:shift_expr; // !? /* ---------------------------------------------------------------------- */ /* try statement */ try_stat : "try" body:compound_stat handlers:handler_list ; handler_list : handler ( handler)* ; handler : "catch" '(' ( type:common_type_id | "..." ) ')' body:compound_stat ; /* throw expression */ throw_expr : "throw" (expr:assignment_expr)? ; /* exception specification */ exception_specification : "throw" '(' ( exception_specification_item (',' exception_specification_item)* )? ')' ; exception_specification_item : type:type_id ; /* ---------------------------------------------------------------------- */