/** 语句 <statement>::=<compound_statement> |<if_statement> |<return_statement> |<break_statement> |<continue_statement> |for_statement> <expression_statement> */ void statement(){ switch(token){ case TK_BEGIN: compound_statement(); break; case KW_IF: if_statement(); break; case KW_RETURN: return_statement(); break; case KW_BREAK: break_statement(); break; case KW_CONTINUE: continue_statement(); break; case KW_FOR: for_statement(); break; default: expression_statement(); break; } get_token(); /// }
static Boolean_t handler( void ) { if( token( 0 ) == SN_CATCH ) { step( 1 ); if( token( 0 ) == '(' ) { int i = 1; step( 1 ); while( i > 0 ) { switch( token( 0 )) { case '(': i++; break; case ')': i--; break; } step( 1 ); } } compound_statement(); return True; } else { return False; } }
static Boolean_t try_statement( void ) { step( 1 ); compound_statement(); handler_list(); return True; }
int statement(void) { if( labeled_statement() ) { } else if( compound_statement() ) { } else if( expression_statement() ) { } else if( selection_statement() ) { } else if( iteration_statement() ) { } else if( jump_statement() ) { } else { abort(); } }
int function_definition(void) { if( declaration_specifiers() ) { declarator(); if( declaration_list() ) { } } else if ( declarator() ) { if( declaration_list() ) { } } else { abort(); } compound_statement(); }
// Parse a statement. // // statement: // compound-statement // return-statement // ... // declaration-statement Stmt& Parser::statement() { switch (lookahead()) { case lbrace_tok: return compound_statement(); case return_tok: return return_statement(); case var_tok: case def_tok: case struct_tok: case class_tok: case enum_tok: case namespace_tok: case template_tok: return declaration_statement(); default: return expression_statement(); } }
TOKEN function_definition(SYMBOL s) { TOKEN func_definition = NULL; //we didn't find a global var so assume we found a function //we already parsed the declaration specifiers and the declarator in the earlier parsing attempt //so just repurpose the information we collected instead of backtracking and re-parsing expect(DELIMITER_TOKEN, OPEN_PAREN, NO_ERROR_HANDLER); TOKEN params = parameter_type_list(); //we already found the return type and function name earlier, so we just pick up from there expect(DELIMITER_TOKEN, CLOSE_PAREN, NO_ERROR_HANDLER); SYMBOL return_type = s; insertfn(s->namestring, return_type, get_token_symbol_type(params)); //FIXME: extend this to more than just one parameter TOKEN func_body = compound_statement(); //FIXME: this is a hack to retrieve the function name in TOKEN form //figure out a better way to deal with this TOKEN func_name = make_token(); set_token_type(func_name, IDENTIFIER_TOKEN); set_token_string_value(func_name, s->namestring); set_token_symbol_table_entry(func_name, s); params = make_statement_list(params); func_definition = make_function_definition(func_name, params, func_body); return func_definition; }
/** 函数体 <funcbody>::=<compound_statement> */ void funcbody(){ compound_statement(); }
extern Boolean_t f_CompoundStatement( char *types, char *names ) { int retval; /* printf( "Compund Statement: (%s) (%s)\n", types, names ); */ if( SymtabVariable == 0 ) { SymtabVariable = SymtabCreate((void (*)(void*)) f_TypeDestroy ); } if( SymtabClass == 0 ) { SymtabClass = SymtabCreate((void (*)(void*)) f_ClassDestroy ); } if( types && names ) { /* feldolgozzuk a fuggveny argumentum listat */ char *my_types, *types_beg, *types_end; char *my_names, *names_beg, *names_end; int iBreak; my_types = SN_StrDup( types ); my_names = SN_StrDup( names ); types_beg = my_types; names_beg = my_names; iBreak = False; while( ! iBreak ) { if(( types_end = my_strchr( types_beg, ',' ))) { *types_end = 0; } else { iBreak = True; } if(( names_end = my_strchr( names_beg, ',' ))) { *names_end = 0; } else { iBreak = True; } if( *names_beg && types_beg[0] != '.' ) { Type_t Type; Type = f_TypeFromString( types_beg ); if( Type == 0 ) { /* 24.02.97 rigo */ /* int DEFUN(_IO_fflush, (fp), register _IO_FILE *fp ){} eseten elofordul */ /* f_InternalError( 61 ); */ Type = f_TypeCreateInt(); } if( Type->Declarator == 0 ) { Type->Declarator = f_DeclaratorCreate(); Type->Declarator->Name = f_NameCreate( names_beg ); } else { if( Type->Declarator->Name ) { f_InternalError( 62 ); } else { Type->Declarator->Name = f_NameCreate( names_beg ); } } /* felodjuk az esetleges typedef-eket */ Type = f_TypeBasic( Type, start_lineno_g - 1 ); if( SymtabInsert( SymtabVariable , Type->Declarator->Name->pcName , (void *) Type , niveauComp )) { #ifdef SYMTAB_TRACE char acType[10000]; /* old: 1000 */ f_TypeToString( Type, acType, 1 ); printf( "argument type: %s ----- name: %s\n" , acType , Type->Declarator->Name->pcName ); #endif } else { f_TypeDestroy( Type ); } } if( ! iBreak ) { types_beg = types_end + 1; names_beg = names_end + 1; } } ckfree( my_names ); ckfree( my_types ); } retval = compound_statement(); #ifdef SYMTAB_TRACE printf( "vor Clear\n" ); SymtabPrint( SymtabVariable, 0 ); #endif SymtabClear( SymtabVariable ); SymtabClear( SymtabClass ); #ifdef SYMTAB_TRACE printf( "after Clear\n" ); SymtabPrint( SymtabVariable, 0 ); #endif return retval; }
static Boolean_t statement( void ) { /* printf( "statement: %s\n", ident( 0 )); */ switch( token( 0 )) { case ';' : step( 1 ); return True; case '{' : return compound_statement(); case SN_CASE : return case_statement(); case SN_DEFAULT : return default_statement(); case SN_IF : return if_statement(); case SN_ELSE : return else_statement(); case SN_SWITCH : return switch_statement(); case SN_WHILE : return while_statement(); case SN_DO : return do_statement(); case SN_FOR : return for_statement(); case SN_BREAK : return break_statement(); case SN_CONTINUE : return continue_statement(); case SN_RETURN : return return_statement(); case SN_THROW : return throw_statement(); case SN_GOTO : return goto_statement(); case SN_TRY : return try_statement(); case SN_IDENTIFIER: if( labeled_statement ()) return True; if( declaration_statement1()) return True; if( expression_statement ()) return True; if( declaration_statement2()) return True; step( 1 ); return False; case SN_CHAR : case SN_SHORT : case SN_INT : case SN_LONG : case SN_SIGNED : case SN_UNSIGNED : case SN_FLOAT : case SN_DOUBLE : case SN_BOOL : case SN_VOID : if( declaration_statement1()) return True; if( expression_statement ()) return True; if( declaration_statement2()) return True; step( 1 ); return False; case SN_ASM : case SN_TEMPLATE : case SN_NAMESPACE: case SN_USING : case SN_AUTO : case SN_REGISTER : case SN_EXTERN : case SN_STATIC : case SN_INLINE : case SN_VIRTUAL : case SN_CONST : case SN_VOLATILE : case SN_CLASS : case SN_STRUCT : case SN_UNION : case SN_ENUM : case SN_FRIEND : case SN_TYPEDEF : if( declaration_statement1()) return True; if( declaration_statement2()) return True; f_StepTo( ';', '}', 0 ); return False; case SN_SIZEOF : case SN_NEW : case SN_DELETE : case SN_THIS : case SN_OPERATOR : case SN_STRINGliteral : case SN_FLOATINGconstant : case SN_INTEGERconstant : case SN_LONGconstant : case SN_CHARACTERconstant : case SN_ICR : case SN_DECR : case SN_CLCL : case '(': case '~': case '*': case '&': case '+': case '-': case '!': if( expression_statement ()) return True; step( 1 ); return False; case 0: printf( "unexpected end of file\n" ); return False; default: #ifdef PRINT_STATEMENT_DEFAULT printf( "statement: default: %4d %s file: %s:(%d.%d)\n" , token( 0 ) , ident( 0 ) , filename_g , f_lineno( 0 ) , f_charno( 0 ) ); #endif #ifdef BREAK_BY_STATEMENT_DEFAULT exit( -1 ); #endif if( declaration_statement1()) return True; if( expression_statement ()) return True; if( declaration_statement2()) return True; step( 1 ); return False; /* case SN_ARROW : */ /* case SN_LS : */ /* case SN_RS : */ /* case SN_LE : */ /* case SN_GE : */ /* case SN_EQ : */ /* case SN_NE : */ /* case SN_ANDAND : */ /* case SN_OROR : */ /* case SN_ELLIPSIS : */ /* case SN_DOTstar : */ /* case SN_ARROWstar : */ /* case SN_MULTassign : */ /* case SN_DIVassign : */ /* case SN_MODassign : */ /* case SN_PLUSassign : */ /* case SN_MINUSassign : */ /* case SN_LSassign : */ /* case SN_RSassign : */ /* case SN_ANDassign : */ /* case SN_ERassign : */ /* case SN_ORassign : */ /* case '=' : */ /* case '|' : */ /* case '^' : */ /* case '&' : */ /* case '<' : */ /* case '>' : */ /* case '/' : */ /* case '%' : */ /* case ')' : */ /* case '[' : */ /* case ']' : */ /* case '.' : */ /* case ',' : */ /* case '{' : */ /* case '}' : */ /* case '?' : */ /* case ':' : */ } }