%{ #include #include #include #include "y.tab.h" FILE* yyin; FILE* yyout; #define TRANSFER_SYNTAX_NDR32 //or NDR64 extern int yylex(void); void yyerror(char*); void print_debug(FILE*, char*); void print_warning(FILE*, char*); %} %union { char* text; } %token tCOMMENT %token tINTCONST %token tREALCONST %token tCHARCONST %token tSTRINGCONST %token tUUIDCONST /*RESERVED WORDS*/ %token tFALSE %token tNULL %token tTRUE %token tBOOLEAN %token tBYTE %token tCASE %token tCHAR %token tCONST %token tDEFAULT %token tDOUBLE %token tENUM %token tERRORSTATUST %token tFLOAT %token tHANDLET %token tHYPER %token tIMPORT %token tINT %token tINTERFACE %token tLONG %token tSHORT %token tSIGNED %token tSMALL %token tSTRUCT %token tSWITCH %token tTYPEDEF %token tUNION %token tUNSIGNED %token tVOID /*MICROSOFT IDL (MIDL) extensions to reserved words*/ %token tMSUNION %token tWCHART %token tSIZEOF /*RESERVED WORDS IN ATTRIBUTE CONTEXT*/ %token tBROADCAST //%token tCASE already defined %token tCONTEXTHANDLE %token tENDPOINT %token tEXCEPTIONS %token tFIRSTIS %token tHANDLE %token tIDEMPOTENT %token tIGNORE %token tIN %token tLASTIS %token tLENGTHIS %token tLOCAL %token tMAYBE %token tMAXIS %token tMINIS %token tOUT %token tPOINTERDEFAULT %token tPTR %token tREF %token tREFLECTDELETIONS %token tSIZEIS %token tSTRING %token tSWITCHIS %token tSWITCHTYPE %token tTRANSMITAS %token tUNIQUE %token tUUID %token tVERSION %token tWIREMARSHAL /*MICROSOFT IDL (MIDL) extensions to reserved words*/ %token tHELPSTRING %token tRANGE %token tIDENTIFIER %% idl: interface { print_debug(NULL, "PARSING"); } interface: interface_header '{' interface_body '}' interface_header: '[' interface_attributes ']' tINTERFACE tIDENTIFIER interface_attributes: interface_attribute | interface_attributes ',' interface_attribute interface_attribute: tUUID '(' tUUIDCONST ')' | tVERSION '(' tREALCONST ')' | tENDPOINT '(' string_list ')' | tEXCEPTIONS '(' excep_name_list ')' | tLOCAL | tPOINTERDEFAULT '(' ptr_attr ')' | tMSUNION string_list: tSTRINGCONST | string_list ',' tSTRINGCONST excep_name_list: tIDENTIFIER | excep_name_list ',' tIDENTIFIER interface_body: imports interface_components | interface_components imports: import ';' | imports import ';' interface_components: interface_component | interface_components interface_component import: tIMPORT import_list import_list: string_list interface_component: export | op_declarator ';' export: type_declarator ';' | const_declarator ';' | tagged_declarator ';' const_declarator: tCONST const_type_spec tIDENTIFIER '=' const_exp const_type_spec: primitive_integer_type | tCHAR | tBOOLEAN | tVOID '*' | tCHAR '*' const_exp: integer_const_exp | tIDENTIFIER | tSTRINGCONST | tCHARCONST | tNULL | tTRUE | tFALSE integer_const_exp: conditional_exp conditional_exp: logical_or_exp | logical_or_exp '?' integer_const_exp ':' conditional_exp logical_or_exp: logical_and_exp | logical_or_exp '|' '|' logical_and_exp logical_and_exp: inclusive_or_exp | logical_and_exp '&' '&' inclusive_or_exp inclusive_or_exp: exclusive_or_exp | inclusive_or_exp '|' exclusive_or_exp exclusive_or_exp: and_exp | exclusive_or_exp '^' and_exp and_exp: equality_exp | and_exp '&' equality_exp equality_exp: relational_exp | equality_exp '=' '=' relational_exp | equality_exp '!' '=' relational_exp relational_exp: shift_exp | relational_exp '<' '<' '>' shift_exp | relational_exp '<' '>' '>' shift_exp | relational_exp '<' '<' '=' '>' shift_exp | relational_exp '<' '>' '=' '>' shift_exp shift_exp: additive_exp | shift_exp '<' '<' '<' '>' additive_exp | shift_exp '<' '>' '>' '>' additive_exp additive_exp: multiplicative_exp | additive_exp '+' multiplicative_exp | additive_exp '-' multiplicative_exp multiplicative_exp: unary_exp | multiplicative_exp '*' unary_exp | multiplicative_exp '/' unary_exp | multiplicative_exp '%' unary_exp unary_exp: primary_exp | '+' primary_exp | '-' primary_exp | '~' primary_exp | '!' primary_exp primary_exp: tINTCONST | tIDENTIFIER | '(' const_exp ')' | sizeof_exp sizeof_exp: tSIZEOF '(' tIDENTIFIER ')' | tSIZEOF '(' base_type_spec ')' type_declarator: tTYPEDEF type_spec declarators | tTYPEDEF '[' type_attribute_list ']' type_spec declarators type_attribute_list: type_attribute | type_attribute_list ',' type_attribute type_spec: simple_type_spec | constructed_type_spec simple_type_spec: base_type_spec | predefined_type_spec | tIDENTIFIER declarators: declarator_list declarator_list: declarator | declarator_list ',' declarator declarator: pointer_opt direct_declarator direct_declarator: tIDENTIFIER | '(' declarator ')' | array_declarator | function_declarator tagged_declarator: tagged_struct_declarator | tagged_union_declarator base_type_spec: floating_pt_type | integer_type | char_type | boolean_type | byte_type | void_type | handle_type | wchar_type floating_pt_type: tFLOAT | tDOUBLE integer_type: primitive_integer_type | tHYPER | tHYPER tINT | tHYPER tUNSIGNED | tHYPER tUNSIGNED tINT | tUNSIGNED tHYPER | tUNSIGNED tHYPER tINT primitive_integer_type: signed_integer | unsigned_integer signed_integer: integer_size | integer_size tINT | tINT unsigned_integer: integer_size tUNSIGNED tINT | integer_size tUNSIGNED | tUNSIGNED integer_size | tUNSIGNED integer_size tINT | tUNSIGNED tINT integer_size: tLONG | tSHORT | tSMALL char_type: tUNSIGNED tCHAR | tCHAR wchar_type: tWCHART boolean_type: tBOOLEAN byte_type: tBYTE void_type: tVOID handle_type: tHANDLET constructed_type_spec: struct_type | union_type | enumeration_type | tagged_declarator //| pipe_type tagged_struct_declarator: tSTRUCT tag | tagged_struct struct_type: tSTRUCT '{' member_list '}' tagged_struct: tSTRUCT tag '{' member_list '}' tag: tIDENTIFIER member_list: member | member_list member member: field_declarator ';' field_declarator: '[' field_attribute_list ']' type_spec declarators | type_spec declarators field_attribute_list: field_attribute | field_attribute_list ',' field_attribute tagged_union_declarator: tUNION tag | tagged_union union_type: tUNION union_switch '{' union_body '}' | tUNION '{' union_body_n_e '}' union_switch: tSWITCH '(' switch_type_spec tIDENTIFIER ')' | tSWITCH '(' switch_type_spec tIDENTIFIER ')' union_name switch_type_spec: primitive_integer_type | char_type | boolean_type | tIDENTIFIER tagged_union: tUNION tag union_switch '{' union_body '}' | tUNION tag '{' union_body_n_e '}' union_name: tIDENTIFIER union_body: union_cases union_cases: union_case | union_cases union_case union_body_n_e: union_cases_n_e union_cases_n_e: union_case_n_e | union_cases_n_e union_case_n_e union_case: union_case_labels union_arm | default_case union_case_labels: union_case_label | union_case_labels union_case_label union_case_n_e: union_case_labels_n_e union_arm | default_case_n_e union_case_labels_n_e: union_case_label_n_e | union_case_labels_n_e union_case_label_n_e union_case_label: tCASE const_exp ':' union_case_label_n_e: '[' tCASE '(' const_exp_list ')' ']' const_exp_list: const_exp | const_exp_list ',' const_exp default_case: tDEFAULT ':' union_arm default_case_n_e: '[' tDEFAULT ']' union_arm union_arm: field_declarator ';' | ';' union_type_switch_attr: tSWITCHTYPE '(' switch_type_spec ')' union_instance_switch_attr: tSWITCHIS '(' attr_var ')' enumeration_type: tENUM '{' enum_body '}' enum_body: enum_body_entry | enum_body ',' enum_body_entry enum_body_entry: tIDENTIFIER | tIDENTIFIER '=' integer_const_exp /*NO PIPE SUPPORT FOR THE TIME BEING*/ //pipe_type: tPIPE type_spec array_declarator: direct_declarator array_bounds_declarator array_bounds_declarator: '[' array_bound ']' // | '[' array_bounds_pair ']' //array_bounds_pair: array_bound '.' '.' array_bound array_bound: '*' | integer_const_exp //| tIDENTIFIER NOTE: this rule is defined further in integer_const_exp | type_attribute: tTRANSMITAS '(' xmit_type ')' | tHANDLE | usage_attribute | union_type_switch_attr | ptr_attr usage_attribute: tSTRING | tCONTEXTHANDLE xmit_type: simple_type_spec field_attribute: tFIRSTIS '(' attr_var_list ')' | tLASTIS '(' attr_var_list ')' | tLENGTHIS '(' attr_var_list ')' | tMINIS '(' attr_var_list ')' | tMAXIS '(' attr_var_list ')' | tSIZEIS '(' attr_var_list ')' | usage_attribute | union_instance_switch_attr | tIGNORE | ptr_attr | tRANGE '(' attr_var_list ')' attr_var_list: attr_var | attr_var_list ',' attr_var attr_var: '*' tIDENTIFIER //| tIDENTIFIER | integer_const_exp | pointer_opt: pointer | ptr_attr: tREF | tUNIQUE | tPTR pointer: '*' | pointer '*' op_declarator: operation_attributes simple_type_spec tIDENTIFIER param_declarators | simple_type_spec tIDENTIFIER param_declarators operation_attributes: '[' operation_attribute_list ']' operation_attribute_list: operation_attribute | operation_attribute_list ',' operation_attribute operation_attribute: tIDEMPOTENT | tBROADCAST | tMAYBE | tREFLECTDELETIONS | usage_attribute | ptr_attr param_declarators: '(' param_declarator_list ')' | '(' ')' | '(' tVOID ')' param_declarator_list: param_declarator | param_declarator_list ',' param_declarator param_declarator: param_attributes type_spec declarator param_attributes: '[' param_attribute_list ']' param_attribute_list: param_attribute | param_attribute_list ',' param_attribute param_attribute: directional_attribute | field_attribute directional_attribute: tIN | tOUT function_declarator: direct_declarator param_declarators predefined_type_spec: tERRORSTATUST //| international_character_type //international_character_type: ISO_LATIN_1 // | ISO_MULTI_LINGUAL // | ISO_UCS %% void print_debug(FILE* fp, char *msg){ if(fp == NULL){ fp = stderr; } fprintf(fp, "[DEBUG] %s\n", msg); } void print_warning(FILE* fp, char *msg){ if(fp == NULL){ fp = stderr; } fprintf(fp, "[WARNING] %s\n", msg); } void yyerror(char *s) { fprintf(stderr,"[ERROR] %s\n",s); return; } int main(int argc, char* argv[]) { yyin = fopen(argv[argc-1], "r" ); if(yyin == NULL) { perror("fopen"); return 2; } yyparse(); return 0; }