Expression *Parser::ParseSExpr() { Token* look = lexer_->GetToken(); switch (look->type()) { case Token::LET: { return ParseLet(false); } case Token::LETREC: { return ParseLet(true); } case Token::CASE: { return ParseCase(); } case Token::LAMBDA: { return ParseLambda(); } case Token::ID: case Token::INT: case Token::PACK: case Token::LPAREN: { // AExpr Or Application Expression* now; now = ParseAExpr(); while (IsAExprStartToken(lexer_->GetToken()->type())) { Expression* arg = ParseAExpr(); now = new EApplication(now->GetToken(), now, arg); } return now; } default: throw ParseException(look, "unexpected token"); } }
Statement *Statement::ParseSwitch() { Statement *snp; Statement *head, *tail; snp = NewStatement(st_switch, TRUE); snp->nkd = false; iflevel++; looplevel++; needpunc(openpa,0); if( expression(&(snp->exp)) == NULL ) error(ERR_EXPREXPECT); if (lastst==semicolon) { NextToken(); if (lastst==kw_naked) { NextToken(); snp->nkd = true; } } needpunc(closepa,0); needpunc(begin,36); head = 0; while( lastst != end ) { if( head == (Statement *)NULL ) { head = tail = ParseCase(); if (head) head->outer = snp; } else { tail->next = ParseCase(); if( tail->next != (Statement *)NULL ) { tail->next->outer = snp; tail = tail->next; } } if (tail==(Statement *)NULL) break; // end of file in switch tail->next = (Statement *)NULL; } snp->s1 = head; NextToken(); if( head->CheckForDuplicateCases() ) error(ERR_DUPCASE); iflevel--; looplevel--; return (snp); }
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--; }
asCScriptNode *asCParser::ParseSwitch() { asCScriptNode *node = new asCScriptNode(snSwitch); sToken t; GetToken(&t); if( t.type != ttSwitch ) { Error(ExpectedToken("switch").AddressOf(), &t); return node; } node->UpdateSourcePos(t.pos, t.length); GetToken(&t); if( t.type != ttOpenParanthesis ) { Error(ExpectedToken("(").AddressOf(), &t); return node; } node->AddChildLast(ParseAssignment()); if( isSyntaxError ) return node; GetToken(&t); if( t.type != ttCloseParanthesis ) { Error(ExpectedToken(")").AddressOf(), &t); return node; } GetToken(&t); if( t.type != ttStartStatementBlock ) { Error(ExpectedToken("{").AddressOf(), &t); return node; } while( !isSyntaxError ) { GetToken(&t); if( t.type == ttEndStatementBlock || t.type == ttDefault) break; RewindTo(&t); if( t.type != ttCase ) { Error(ExpectedToken("case").AddressOf(), &t); return node; } node->AddChildLast(ParseCase()); if( isSyntaxError ) return node; } if( t.type == ttDefault) { RewindTo(&t); node->AddChildLast(ParseCase()); if( isSyntaxError ) return node; GetToken(&t); } if( t.type != ttEndStatementBlock ) { Error(ExpectedToken("}").AddressOf(), &t); return node; } return node; }