Skip to content

Commit

Permalink
'else' fixed, along with semicolon handling
Browse files Browse the repository at this point in the history
git-svn-id: http://picoc.googlecode.com/svn/trunk@175 21eae674-98b7-11dd-bd71-f92a316d2d60
  • Loading branch information
zik.saleeba committed Mar 9, 2009
1 parent 08cd7e8 commit 1b31254
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Bugs:
* defining functions returning void
* defining functions from interactive mode
* defining functions with no parameters (in interactive mode?)
* 'else' is broken
* int fact(int i) {
if (i < 2) {
return i;
Expand Down
19 changes: 16 additions & 3 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ void ParseFor(struct ParseState *Parser)
if (!ParseStatement(Parser))
ProgramFail(Parser, "statement expected");

if (LexGetToken(Parser, NULL, TRUE) != TokenSemicolon)
ProgramFail(Parser, "';' expected");

ParserCopyPos(&PreConditional, Parser);
Condition = ExpressionParseInt(Parser);

Expand Down Expand Up @@ -254,6 +251,7 @@ int ParseStatement(struct ParseState *Parser)
{
struct Value *CValue;
int Condition;
int CheckTrailingSemicolon = TRUE;
struct ParseState PreState = *Parser;
enum LexToken Token = LexGetToken(Parser, NULL, TRUE);

Expand Down Expand Up @@ -291,6 +289,7 @@ int ParseStatement(struct ParseState *Parser)
if (!ParseStatementMaybeRun(Parser, !Condition))
ProgramFail(Parser, "statement expected");
}
CheckTrailingSemicolon = FALSE;
break;

case TokenWhile:
Expand All @@ -309,6 +308,8 @@ int ParseStatement(struct ParseState *Parser)

if (Parser->Mode == RunModeBreak)
Parser->Mode = RunModeRun;

CheckTrailingSemicolon = FALSE;
}
break;

Expand Down Expand Up @@ -337,6 +338,7 @@ int ParseStatement(struct ParseState *Parser)

case TokenFor:
ParseFor(Parser);
CheckTrailingSemicolon = FALSE;
break;

case TokenSemicolon: break;
Expand All @@ -354,6 +356,7 @@ int ParseStatement(struct ParseState *Parser)

case TokenHashDefine:
ParseMacroDefinition(Parser);
CheckTrailingSemicolon = FALSE;
break;

case TokenHashInclude:
Expand All @@ -363,6 +366,7 @@ int ParseStatement(struct ParseState *Parser)
ProgramFail(Parser, "\"filename.h\" expected");

//ScanFile(LexerValue->Val->String); // XXX - need to dereference char * here
CheckTrailingSemicolon = FALSE;
break;
}

Expand All @@ -389,6 +393,8 @@ int ParseStatement(struct ParseState *Parser)
Parser->Mode = OldMode;
Parser->SearchLabel = OldSearchLabel;
}

CheckTrailingSemicolon = FALSE;
break;

case TokenCase:
Expand All @@ -406,6 +412,8 @@ int ParseStatement(struct ParseState *Parser)

if (Parser->Mode == RunModeCaseSearch && Condition == Parser->SearchLabel)
Parser->Mode = RunModeRun;

CheckTrailingSemicolon = FALSE;
break;

case TokenDefault:
Expand All @@ -414,6 +422,8 @@ int ParseStatement(struct ParseState *Parser)

if (Parser->Mode == RunModeCaseSearch)
Parser->Mode = RunModeRun;

CheckTrailingSemicolon = FALSE;
break;

case TokenBreak:
Expand Down Expand Up @@ -447,6 +457,9 @@ int ParseStatement(struct ParseState *Parser)
return FALSE;
}

if (CheckTrailingSemicolon && LexGetToken(Parser, NULL, FALSE) == TokenSemicolon)
LexGetToken(Parser, NULL, TRUE);

return TRUE;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ TESTS= 00_assignment.test \
09_do_while.test \
10_pointer.test \
12_hashdefine.test \
13_integer_literals.test
13_integer_literals.test \
14_if.test

%.test: %.expect %.c
@echo Test: $*...
Expand Down

0 comments on commit 1b31254

Please sign in to comment.