In the following code fragment, I only want to print an error
message when an invalid symbol follows a valid symbol. My
'error_found' and 'error_this_case' handles that, but it seems a
little convoluted. Is there a clearer way?
Symbol get_sym(void);
Symbol sym;
void stmt_seq(void) {
int error_found = 0;
for (;;) {
int error_this_case = 0;
switch (sym) {
case ident_sym : ident_stmt(); break;
case while_sym : while_stmt(); break;
case if_sym: if_stmt(); break;
case endwhile_sym:
case else_sym:
case eof_sym:
return;
default:
if (!error_found)
error("expecting stmt");
error_this_case = 1;
get_sym();
}
if (error_this_case)
error_found = 1;
else
error_found = 0;
}
}