From: Christoph Mallon Date: Thu, 26 Apr 2012 12:53:09 +0000 (+0200) Subject: Improve error recovery in parse_compound_statement(). X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=c080950de05aa3e3e2adf8835387b5d0112bb868;hp=48047e0db53c86b0d6330ff7770d00b723d0bc48;p=cparser Improve error recovery in parse_compound_statement(). - Handle EOF generically with expect(). - Do not skip semantic checks, when breaking out of the parsing loop due to an error. --- diff --git a/parser.c b/parser.c index b1db357..1644fa3 100644 --- a/parser.c +++ b/parser.c @@ -10158,15 +10158,10 @@ static statement_t *parse_compound_statement(bool inside_expression_statement) statement_t **anchor = &statement->compound.statements; bool only_decls_so_far = true; - while (token.kind != '}') { - if (token.kind == T_EOF) { - errorf(&statement->base.source_position, - "EOF while parsing compound statement"); - break; - } + while (token.kind != '}' && token.kind != T_EOF) { statement_t *sub_statement = intern_parse_statement(); if (sub_statement->kind == STATEMENT_ERROR) { - goto end_error; + break; } if (sub_statement->kind != STATEMENT_DECLARATION) { @@ -10179,7 +10174,8 @@ static statement_t *parse_compound_statement(bool inside_expression_statement) *anchor = sub_statement; anchor = &sub_statement->base.next; } - next_token(); + expect('}', end_error); +end_error: /* look over all statements again to produce no effect warnings */ if (is_warn_on(WARN_UNUSED_VALUE)) { @@ -10199,7 +10195,6 @@ static statement_t *parse_compound_statement(bool inside_expression_statement) } } -end_error: rem_anchor_token(T_while); rem_anchor_token(T_wchar_t); rem_anchor_token(T_volatile);