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
This commit is contained in:
zik.saleeba 2010-07-27 11:34:24 +00:00
parent e45e455b9b
commit c0a21f5c37
4 changed files with 39 additions and 4 deletions

14
parse.c
View file

@ -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:

16
tests/45_empty_for.c Normal file
View file

@ -0,0 +1,16 @@
#include <stdio.h>
int main()
{
int Count = 0;
for (;;)
{
Count++;
printf("%d\n", Count);
if (Count >= 10)
break;
}
return 0;
}

10
tests/45_empty_for.expect Normal file
View file

@ -0,0 +1,10 @@
1
2
3
4
5
6
7
8
9
10

View file

@ -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: $*...