From: cuz Date: Thu, 13 Mar 2003 12:35:54 +0000 (+0000) Subject: Added better error recovery X-Git-Tag: V2.12.0~1679 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c8d76046cbdb5dc9c92b619b6a7db7bc63d20fc9;p=cc65 Added better error recovery git-svn-id: svn://svn.cc65.org/cc65/trunk@2013 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/stmt.c b/src/cc65/stmt.c index ab091be3a..408297a18 100644 --- a/src/cc65/stmt.c +++ b/src/cc65/stmt.c @@ -74,22 +74,40 @@ static void CheckTok (token_t Tok, const char* Msg, int* PendingToken) */ { if (CurTok.Tok != Tok) { - Error (Msg); + Error (Msg); } else if (PendingToken) { - *PendingToken = 1; + *PendingToken = 1; } else { - NextToken (); + NextToken (); } } static void CheckSemi (int* PendingToken) -/* Helper function for Statement. Will call CheckTok with the parameters - * for a semicolon. +/* Helper function for Statement. Will check for a semicolon and print an + * error message if not found (plus some error recovery). If PendingToken is + * NULL, it will the skip the token, otherwise it will store one to + * PendingToken. + * This function is a special version of CheckTok with the addition of the + * error recovery. */ { - CheckTok (TOK_SEMI, "`;' expected", PendingToken); + int HaveToken = (CurTok.Tok == TOK_SEMI); + if (!HaveToken) { + Error ("`;' expected"); + /* Try to be smart about errors */ + if (CurTok.Tok == TOK_COLON || CurTok.Tok == TOK_COMMA) { + HaveToken = 1; + } + } + if (HaveToken) { + if (PendingToken) { + *PendingToken = 1; + } else { + NextToken (); + } + } }