From c0a21f5c37fd4cd470f449d2a05316aa693cc6a1 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Tue, 27 Jul 2010 11:34:24 +0000 Subject: [PATCH] Fixed for loops of the form: for (;;) Fixes issue 93 git-svn-id: http://picoc.googlecode.com/svn/trunk@474 21eae674-98b7-11dd-bd71-f92a316d2d60 --- parse.c | 14 +++++++++++--- tests/45_empty_for.c | 16 ++++++++++++++++ tests/45_empty_for.expect | 10 ++++++++++ tests/Makefile | 3 ++- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tests/45_empty_for.c create mode 100644 tests/45_empty_for.expect diff --git a/parse.c b/parse.c index 56535a3..19c0069 100644 --- a/parse.c +++ b/parse.c @@ -334,7 +334,10 @@ void ParseFor(struct ParseState *Parser) ProgramFail(Parser, "statement expected"); ParserCopyPos(&PreConditional, Parser); - Condition = ExpressionParseInt(Parser); + if (LexGetToken(Parser, NULL, FALSE) == TokenSemicolon) + Condition = TRUE; + else + Condition = ExpressionParseInt(Parser); if (LexGetToken(Parser, NULL, TRUE) != TokenSemicolon) ProgramFail(Parser, "';' expected"); @@ -360,7 +363,10 @@ void ParseFor(struct ParseState *Parser) ParseStatement(Parser, FALSE); ParserCopyPos(Parser, &PreConditional); - Condition = ExpressionParseInt(Parser); + if (LexGetToken(Parser, NULL, FALSE) == TokenSemicolon) + Condition = TRUE; + else + Condition = ExpressionParseInt(Parser); if (Condition) { @@ -555,7 +561,9 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi CheckTrailingSemicolon = FALSE; break; - case TokenSemicolon: break; + case TokenSemicolon: + CheckTrailingSemicolon = FALSE; + break; case TokenIntType: case TokenShortType: diff --git a/tests/45_empty_for.c b/tests/45_empty_for.c new file mode 100644 index 0000000..28d0b6c --- /dev/null +++ b/tests/45_empty_for.c @@ -0,0 +1,16 @@ +#include + +int main() +{ + int Count = 0; + + for (;;) + { + Count++; + printf("%d\n", Count); + if (Count >= 10) + break; + } + + return 0; +} diff --git a/tests/45_empty_for.expect b/tests/45_empty_for.expect new file mode 100644 index 0000000..f00c965 --- /dev/null +++ b/tests/45_empty_for.expect @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff --git a/tests/Makefile b/tests/Makefile index 8357f11..92f742f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -39,7 +39,8 @@ TESTS= 00_assignment.test \ 40_stdio.test \ 41_hashif.test \ 43_void_param.test \ - 44_scoped_declarations.test + 44_scoped_declarations.test \ + 45_empty_for.test %.test: %.expect %.c @echo Test: $*...