E
Ed Davis
The following is a code fragment from a simple parser.
The return is buried inside the switch statement (the actual
switch has several more cases). I can't come up with a good
alternative I like better. Any ideas? I've tried the 'while
(!done)' approach, but keeping track of the flag doesn't seem any
better than the embedded 'return'.
Symbol get_sym(void);
Symbol sym;
void stmt_seq(void) {
for (; {
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 endif_sym:
case eof_sym:
return;
default:
error("expecting stmt");
get_sym();
}
}
}
The return is buried inside the switch statement (the actual
switch has several more cases). I can't come up with a good
alternative I like better. Any ideas? I've tried the 'while
(!done)' approach, but keeping track of the flag doesn't seem any
better than the embedded 'return'.
Symbol get_sym(void);
Symbol sym;
void stmt_seq(void) {
for (; {
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 endif_sym:
case eof_sym:
return;
default:
error("expecting stmt");
get_sym();
}
}
}