/// definition ::= 'def' prototype expression static FunctionAST *ParseDefinition() { getNextToken(); // eat def. PrototypeAST *Proto = ParsePrototype(); if (Proto == 0) return 0; if (ExprAST *E = ParseExpression()) return new FunctionAST(Proto, E); return 0; }
/// definition ::= 'def' prototype expression static std::unique_ptr<FunctionAST> ParseDefinition() { getNextToken(); // eat def. auto Proto = ParsePrototype(); if (!Proto) return nullptr; if (auto E = ParseExpression()) return helper::make_unique<FunctionAST>(std::move(Proto), std::move(E)); return nullptr; }
// definition ::= 'def' prototype expression std::unique_ptr<CFunctionAST> CParser::ParseDefinition() { GetNextToken(); // eating "def" auto p = ParsePrototype(); if (!p) return nullptr; auto e = ParseExpression(); if (!e) return nullptr; return std::make_unique<CFunctionAST>(std::move(p), std::move(e)); }
/* definition * ::= 'def' prototype expression * */ static shared_ptr<FunctionAST> ParseDefinition() { getNextToken(); // eat def. shared_ptr<PrototypeAST> Proto = ParsePrototype(); vector<shared_ptr<ExprAST> > body; if (Proto == 0) return 0; while (shared_ptr<ExprAST> E = ParseLocalExpression()) { if (CurTok == T_END) { body.push_back(E); getNextToken(); //eat T_END return shared_ptr<FunctionAST>(new FunctionAST(Proto, body)); } else body.push_back(E); } if (CurTok == -1) Error("function definition should end by 'end'"); else Error("invalid expression statement"); return 0; }
/* * Handle function definitions, where * definition ::= 'def' prototype expression */ static std::unique_ptr<FunctionAST> ParseDefinition() { getNextToken(); // advance past the definition auto proto = ParsePrototype(); if (!proto) { return nullptr; } if (auto expr = ParseExpression()) { return llvm::make_unique<FunctionAST>(std::move(proto), std::move(expr)); } else { return nullptr; } }
DefAST *Parser::ParseFuncDefinition() { FTag tag = Lex.tag(); // definitions usually span several lines, so save tag for now. Lex.gettok(); // eat 'func' if (Lex.tok != tok_identifier) Lex.tag().Throw("Expected identifier after 'func'."); std::string name = Lex.tokStr; Lex.gettok(); // eat function name if (Lex.tokStr != ":") Lex.tag().Throw("Expected ':' in function definition."); Lex.gettok(); FuncTypeAST *type = ParsePrototype(); if (type == 0) return 0; if (Lex.tok == tok_extern) { ExternAST *v = dynamic_cast<ExternAST*>(ParseExtern()); return new ExternFuncDefAST(tag, name, v, type); } else { BlockAST *b = dynamic_cast<BlockAST*>(ParseBlock()); if (b == 0) return 0; return new FuncDefAST(tag, name, new FuncExprAST(tag, type, b)); } }
/// external ::= 'extern' prototype static shared_ptr<PrototypeAST> ParseExtern() { getNextToken(); // eat extern. return ParsePrototype(); }
/// external ::= 'extern' prototype static PrototypeAST *ParseExtern() { getNextToken(); // eat extern. return ParsePrototype(); }
/* * Handle external prototypes, where * external ::= 'extern' prototype */ static std::unique_ptr<PrototypeAST> ParseExtern() { getNextToken(); // advance past 'extern' return ParsePrototype(); }
/// external ::= 'extern' prototype static std::unique_ptr<PrototypeAST> ParseExtern() { getNextToken(); // eat extern. return ParsePrototype(); }
// external ::= 'extern' prototype std::unique_ptr<CPrototypeAST> CParser::ParseExtern() { GetNextToken(); // eating "extern" return ParsePrototype(); }