asCScriptNode *asCParser::ParseStatement() { sToken t1; GetToken(&t1); RewindTo(&t1); if( t1.type == ttIf ) return ParseIf(); else if( t1.type == ttFor ) return ParseFor(); else if( t1.type == ttWhile ) return ParseWhile(); else if( t1.type == ttReturn ) return ParseReturn(); else if( t1.type == ttStartStatementBlock ) return ParseStatementBlock(); else if( t1.type == ttBreak ) return ParseBreak(); else if( t1.type == ttContinue ) return ParseContinue(); else if( t1.type == ttDo ) return ParseDoWhile(); else if( t1.type == ttSwitch ) return ParseSwitch(); else return ParseExpressionStatement(); }
asCScriptNode *asCParser::ParseCase() { asCScriptNode *node = new asCScriptNode(snCase); sToken t; GetToken(&t); if( t.type != ttCase && t.type != ttDefault ) { Error(ExpectedTokens("case", "default").AddressOf(), &t); return node; } node->UpdateSourcePos(t.pos, t.length); if(t.type == ttCase) { node->AddChildLast(ParseExpression()); } GetToken(&t); if( t.type != ttColon ) { Error(ExpectedToken(":").AddressOf(), &t); return node; } // Parse statements until we find either of }, case, default, and break GetToken(&t); RewindTo(&t); while( t.type != ttCase && t.type != ttDefault && t.type != ttEndStatementBlock && t.type != ttBreak ) { node->AddChildLast(ParseStatement()); if( isSyntaxError ) return node; GetToken(&t); RewindTo(&t); } // If the case was ended with a break statement, add it to the node if( t.type == ttBreak ) node->AddChildLast(ParseBreak()); return node; }
static void ParseStatement (scontext_t owner) { if (StatementIndex == MAX_STATEMENT_DEPTH) { PR_ParseError("statement overflow"); } ContextHistory[StatementIndex++] = owner; if (TK_CHECK(TK_LBRACE)) { ContextLevel += EnterContext[owner]; do { ParseStatement(owner); } while (!TK_CHECK(TK_RBRACE)); ContextLevel -= EnterContext[owner]; StatementIndex--; return; } if (TK_CHECK(TK_SEMICOLON)) { StatementIndex--; return; } if (LX_CheckFetch("return")) { ParseReturn(); StatementIndex--; return; } if (LX_CheckFetch("loop")) { ParseLoop(); StatementIndex--; return; } if (LX_CheckFetch("while")) { ParseWhile(); StatementIndex--; return; } if (LX_CheckFetch("until")) { ParseUntil(); StatementIndex--; return; } if (LX_CheckFetch("do")) { ParseDo(); StatementIndex--; return; } if (LX_CheckFetch("switch")) { ParseSwitch(); StatementIndex--; return; } if (LX_CheckFetch("case")) { if (owner != SCONTEXT_SWITCH) { PR_ParseError("misplaced case"); } ParseCase(); StatementIndex--; return; } if (LX_CheckFetch("break")) { if (BreakAncestor() == false) { PR_ParseError("misplaced break"); } ParseBreak(); StatementIndex--; return; } if (LX_CheckFetch("continue")) { if (ContinueAncestor() == false) { PR_ParseError("misplaced continue"); } ParseContinue(); StatementIndex--; return; } if (LX_CheckFetch("default")) { ParseDefault(); StatementIndex--; return; } if (LX_CheckFetch("thinktime")) { ParseThinktime(); StatementIndex--; return; } if (LX_CheckFetch("local")) { ParseLocalDefs(); StatementIndex--; return; } if (LX_Check("float") || LX_Check("vector") || LX_Check("entity") || LX_Check("string") || LX_Check("void")) { ParseLocalDefs(); StatementIndex--; return; } if (LX_CheckFetch("if")) { ParseIf(); StatementIndex--; return; } EX_Expression(TOP_PRIORITY); LX_Require(";"); StatementIndex--; }