Recursive Decent Parsing:Error Handling by finding the semi-colon
To complete the panic-mode error recovery, the topmost parsing function must detect the failure to parse and skip forward until a semi-colon is found. Once the semi-colon is found, one more token of look ahead is read; this prepares the parser to resume parsing after the statement with the syntax error. The code for this looks something like this:
scanner(); /* load first look-ahead token */
while( tokentype != T_EOF ){
/* other statement types will go here */
errprint(Unknown statement type);
/* Skip forward to EOF or to after next semi-colon */
while( tokentype != T_SEMI
if( tokentype == T_SEMI )
scanner(); /* skip the ; */