/** * compound statement * allow any number of statements to fall between "{" and "}" * 'func' is true if we are in a "function_statement", which * must contain "statement_list" */ void do_compound(int func) { int decls; decls = YES; ncmp++; while (!match ("}")) { if (input_eof) return; if (decls) { if (!statement_declare ()) decls = NO; } else do_statement (); } ncmp--; }
/** * statement parser * called whenever syntax requires a statement. this routine * performs that statement and returns a number telling which one * @param func func is true if we require a "function_statement", which * must be compound, and must contain "statement_list" (even if * "declaration_list" is omitted) * @return statement type */ statement (int func) { if ((ch () == 0) & feof (input)) return (0); lastst = 0; if (func) if (match ("{")) { do_compound (YES); return (lastst); } else error ("function requires compound statement"); if (match ("{")) do_compound (NO); else do_statement (); return (lastst); }
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 ':' : */ } }