/* localexpression * ::= assignment | returnexpr * */ static shared_ptr<ExprAST> ParseLocalExpression() { if (CurTok == T_RETURN) return ParseReturnExpr(); if (CurTok == T_IDENTIFIER) return ParseAssignmentExpr(); if (CurTok == T_WHILE) return ParseWhileExpr(); if (CurTok == T_IF) return ParseIfExpr(); return 0; }
/* toplevelexpr * ::= expression * ::= assignment * ::= conditionexpr * */ static shared_ptr<ExprAST> ParseTopLevelExpr() { shared_ptr<ExprAST> E; if (CurTok == T_WHILE) E = ParseWhileExpr(); else if (CurTok == T_IF) E = ParseIfExpr(); else if (CurTok == T_IDENTIFIER) E = ParseAssignmentExpr(); else Error("invalid expression statement"); if (E) { return E; } else return 0; }
/// primary /// ::= identifierexpr /// ::= numberexpr /// ::= parenexpr std::unique_ptr<ExprAST> UDFParser::ParsePrimary() { switch (cur_tok_) { default: return LogError("unknown token when expecting an expression"); case tok_identifier: return ParseIdentifierExpr(); case tok_number: return ParseNumberExpr(); case '(': return ParseParenExpr(); case tok_return: return ParseReturn(); case tok_if: return ParseIfExpr(); case tok_semicolon: return nullptr; } }
// primary // ::= identifierexpr // ::= numberexpr // ::= parenexpr // ::= ifexpr // ::= forexpr // ::= varexpr std::unique_ptr<CExprAST> CParser::ParsePrimary() { switch (m_CurrentToken) { default: return LogError("unknown token when expecting an expression!"); case tIdentifier: return ParseIdentifierExpr(); case tNumber: return ParseNumber(); case '(': return ParseParenExpr(); case tIf: return ParseIfExpr(); case tFor: return ParseForExpr(); case tVar: return ParseVarExpr(); } }