ExprAST *Parser::parsePrimary () { // At the top level, we have to have either an identifier of some kind, // a number, or an open paren. We might also have a unary minus sign, handle // that specially right here. switch (currentToken) { case TOKEN_IDENTIFIER_FUNCTION: return parseFunctionIdentifierExpr (); case TOKEN_IDENTIFIER_CONSTANT: return parseConstantIdentifierExpr (); case TOKEN_IDENTIFIER_VARIABLE: return parseVariableIdentifierExpr (); case TOKEN_NUMBER: return parseNumberExpr (); case TOKEN_PAREN_OPEN: return parseOpenParenExpr (); case TOKEN_OPERATOR: if (strToken == "-") return parseUnaryMinusExpr (); // Fall through for any other operator default: error (boost::format ("Expecting an expression, got %1% instead!") % formatToken ()); return NULL; } }
std::unique_ptr<ExprAST> Parser::parsePrimary(s_cursor_t &it, const s_cursor_t &end) { switch (_curTok) { case tok_identifier: return parseIdentifierExpr(it, end); case tok_number: return parseNumberExpr(it, end); case '(': return parseParenExpr(it, end); default: return Error("unknown token when expecting an expression"); } }