Fixed for loop initialisers with variable declarations
This commit is contained in:
parent
9d2327b8be
commit
97030639f1
|
@ -1,10 +1,10 @@
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int j = 0;
|
int j = 999;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
j = i + 2;
|
j = i - 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1892,7 +1892,7 @@ void ExpressionParseFunctionCall(struct ParseState *Parser,
|
||||||
|
|
||||||
Parser->ScopeID = OldScopeID;
|
Parser->ScopeID = OldScopeID;
|
||||||
|
|
||||||
if (ParseStatement(&FuncParser, true) != ParseResultOk)
|
if (ParseStatement(&FuncParser, true, false) != ParseResultOk)
|
||||||
ProgramFail(&FuncParser, "function body expected");
|
ProgramFail(&FuncParser, "function body expected");
|
||||||
|
|
||||||
if (RunIt) {
|
if (RunIt) {
|
||||||
|
|
|
@ -551,7 +551,7 @@ extern void LexInteractiveStatementPrompt(Picoc *pc);
|
||||||
* void PicocParseInteractive(); */
|
* void PicocParseInteractive(); */
|
||||||
extern void PicocParseInteractiveNoStartPrompt(Picoc *pc, int EnableDebugger);
|
extern void PicocParseInteractiveNoStartPrompt(Picoc *pc, int EnableDebugger);
|
||||||
extern enum ParseResult ParseStatement(struct ParseState *Parser,
|
extern enum ParseResult ParseStatement(struct ParseState *Parser,
|
||||||
int CheckTrailingSemicolon);
|
int CheckTrailingSemicolon, int DoNotConsumeTrailingSemicolon);
|
||||||
extern struct Value *ParseFunctionDefinition(struct ParseState *Parser,
|
extern struct Value *ParseFunctionDefinition(struct ParseState *Parser,
|
||||||
struct ValueType *ReturnType, char *Identifier);
|
struct ValueType *ReturnType, char *Identifier);
|
||||||
extern void ParseCleanup(Picoc *pc);
|
extern void ParseCleanup(Picoc *pc);
|
||||||
|
|
28
parse.c
28
parse.c
|
@ -49,11 +49,11 @@ enum ParseResult ParseStatementMaybeRun(struct ParseState *Parser,
|
||||||
enum RunMode OldMode = Parser->Mode;
|
enum RunMode OldMode = Parser->Mode;
|
||||||
int Result;
|
int Result;
|
||||||
Parser->Mode = RunModeSkip;
|
Parser->Mode = RunModeSkip;
|
||||||
Result = ParseStatement(Parser, CheckTrailingSemicolon);
|
Result = ParseStatement(Parser, CheckTrailingSemicolon, false);
|
||||||
Parser->Mode = OldMode;
|
Parser->Mode = OldMode;
|
||||||
return (enum ParseResult)Result;
|
return (enum ParseResult)Result;
|
||||||
} else
|
} else
|
||||||
return ParseStatement(Parser, CheckTrailingSemicolon);
|
return ParseStatement(Parser, CheckTrailingSemicolon, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count the number of parameters to a function or macro */
|
/* count the number of parameters to a function or macro */
|
||||||
|
@ -496,11 +496,11 @@ void ParseFor(struct ParseState *Parser)
|
||||||
ProgramFail(Parser, "'(' expected");
|
ProgramFail(Parser, "'(' expected");
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, false) != TokenSemicolon) {
|
if (LexGetToken(Parser, NULL, false) != TokenSemicolon) {
|
||||||
if (ParseStatement(Parser, false) != ParseResultOk)
|
if (ParseStatement(Parser, false, true) != ParseResultOk)
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
while (LexGetToken(Parser, NULL, false) == TokenComma) {
|
while (LexGetToken(Parser, NULL, false) == TokenComma) {
|
||||||
LexGetToken(Parser, NULL, true);
|
LexGetToken(Parser, NULL, true);
|
||||||
if (ParseStatement(Parser, false) != ParseResultOk)
|
if (ParseStatement(Parser, false, true) != ParseResultOk)
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,10 +538,10 @@ void ParseFor(struct ParseState *Parser)
|
||||||
|
|
||||||
while (Condition && Parser->Mode == RunModeRun) {
|
while (Condition && Parser->Mode == RunModeRun) {
|
||||||
ParserCopyPos(Parser, &PreIncrement);
|
ParserCopyPos(Parser, &PreIncrement);
|
||||||
ParseStatement(Parser, false);
|
ParseStatement(Parser, false, false);
|
||||||
while (LexGetToken(Parser, NULL, false) == TokenComma) {
|
while (LexGetToken(Parser, NULL, false) == TokenComma) {
|
||||||
LexGetToken(Parser, NULL, true);
|
LexGetToken(Parser, NULL, true);
|
||||||
ParseStatement(Parser, false);
|
ParseStatement(Parser, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserCopyPos(Parser, &PreConditional);
|
ParserCopyPos(Parser, &PreConditional);
|
||||||
|
@ -552,7 +552,7 @@ void ParseFor(struct ParseState *Parser)
|
||||||
|
|
||||||
if (Condition) {
|
if (Condition) {
|
||||||
ParserCopyPos(Parser, &PreStatement);
|
ParserCopyPos(Parser, &PreStatement);
|
||||||
ParseStatement(Parser, true);
|
ParseStatement(Parser, true, false);
|
||||||
|
|
||||||
if (Parser->Mode == RunModeContinue)
|
if (Parser->Mode == RunModeContinue)
|
||||||
Parser->Mode = RunModeRun;
|
Parser->Mode = RunModeRun;
|
||||||
|
@ -581,12 +581,12 @@ enum RunMode ParseBlock(struct ParseState *Parser, int AbsorbOpenBrace,
|
||||||
/* condition failed - skip this block instead */
|
/* condition failed - skip this block instead */
|
||||||
enum RunMode OldMode = Parser->Mode;
|
enum RunMode OldMode = Parser->Mode;
|
||||||
Parser->Mode = RunModeSkip;
|
Parser->Mode = RunModeSkip;
|
||||||
while (ParseStatement(Parser, true) == ParseResultOk) {
|
while (ParseStatement(Parser, true, false) == ParseResultOk) {
|
||||||
}
|
}
|
||||||
Parser->Mode = OldMode;
|
Parser->Mode = OldMode;
|
||||||
} else {
|
} else {
|
||||||
/* just run it in its current mode */
|
/* just run it in its current mode */
|
||||||
while (ParseStatement(Parser, true) == ParseResultOk) {
|
while (ParseStatement(Parser, true, false) == ParseResultOk) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,7 +618,7 @@ void ParseTypedef(struct ParseState *Parser)
|
||||||
|
|
||||||
/* parse a statement */
|
/* parse a statement */
|
||||||
enum ParseResult ParseStatement(struct ParseState *Parser,
|
enum ParseResult ParseStatement(struct ParseState *Parser,
|
||||||
int CheckTrailingSemicolon)
|
int CheckTrailingSemicolon, int DoNotConsumeTrailingSemicolon)
|
||||||
{
|
{
|
||||||
int Condition;
|
int Condition;
|
||||||
enum LexToken Token;
|
enum LexToken Token;
|
||||||
|
@ -728,7 +728,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser,
|
||||||
ParserCopyPos(&PreStatement, Parser);
|
ParserCopyPos(&PreStatement, Parser);
|
||||||
do {
|
do {
|
||||||
ParserCopyPos(Parser, &PreStatement);
|
ParserCopyPos(Parser, &PreStatement);
|
||||||
if (ParseStatement(Parser, true) != ParseResultOk)
|
if (ParseStatement(Parser, true, false) != ParseResultOk)
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
if (Parser->Mode == RunModeContinue)
|
if (Parser->Mode == RunModeContinue)
|
||||||
Parser->Mode = PreMode;
|
Parser->Mode = PreMode;
|
||||||
|
@ -894,7 +894,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CheckTrailingSemicolon) {
|
if (CheckTrailingSemicolon) {
|
||||||
if (LexGetToken(Parser, NULL, true) != TokenSemicolon)
|
if (LexGetToken(Parser, NULL, !DoNotConsumeTrailingSemicolon) != TokenSemicolon)
|
||||||
ProgramFail(Parser, "';' expected");
|
ProgramFail(Parser, "';' expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -934,7 +934,7 @@ void PicocParse(Picoc *pc, const char *FileName, const char *Source,
|
||||||
EnableDebugger);
|
EnableDebugger);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Ok = ParseStatement(&Parser, true);
|
Ok = ParseStatement(&Parser, true, false);
|
||||||
} while (Ok == ParseResultOk);
|
} while (Ok == ParseResultOk);
|
||||||
|
|
||||||
if (Ok == ParseResultError)
|
if (Ok == ParseResultError)
|
||||||
|
@ -957,7 +957,7 @@ void PicocParseInteractiveNoStartPrompt(Picoc *pc, int EnableDebugger)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
LexInteractiveStatementPrompt(pc);
|
LexInteractiveStatementPrompt(pc);
|
||||||
Ok = ParseStatement(&Parser, true);
|
Ok = ParseStatement(&Parser, true, false);
|
||||||
LexInteractiveCompleted(pc, &Parser);
|
LexInteractiveCompleted(pc, &Parser);
|
||||||
|
|
||||||
} while (Ok == ParseResultOk);
|
} while (Ok == ParseResultOk);
|
||||||
|
|
Loading…
Reference in a new issue