コード例 #1
0
ファイル: Main.cpp プロジェクト: kpdev42/Kaleidoscope
/// 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;
}
コード例 #2
0
ファイル: toy.cpp プロジェクト: AlexDenisov/llvm
/// 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;
}
コード例 #3
0
ファイル: parser.cpp プロジェクト: reverendhomer/tupac
// 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));
}
コード例 #4
0
/* 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;
}
コード例 #5
0
ファイル: parser.cpp プロジェクト: ornata/llvm-stuff
/*
* 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;
    }
}
コード例 #6
0
ファイル: stmt.cpp プロジェクト: Alexis211/PIF
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));
	}
}
コード例 #7
0
/// external ::= 'extern' prototype
static shared_ptr<PrototypeAST> ParseExtern() {
    getNextToken();  // eat extern.
    return ParsePrototype();
}
コード例 #8
0
ファイル: Main.cpp プロジェクト: kpdev42/Kaleidoscope
/// external ::= 'extern' prototype
static PrototypeAST *ParseExtern() {
  getNextToken();  // eat extern.
  return ParsePrototype();
}
コード例 #9
0
ファイル: parser.cpp プロジェクト: ornata/llvm-stuff
/*
* Handle external prototypes, where
* external ::= 'extern' prototype
*/
static std::unique_ptr<PrototypeAST> ParseExtern()
{
    getNextToken(); // advance past 'extern'
    return ParsePrototype();
}
コード例 #10
0
ファイル: toy.cpp プロジェクト: AlexDenisov/llvm
/// external ::= 'extern' prototype
static std::unique_ptr<PrototypeAST> ParseExtern() {
  getNextToken(); // eat extern.
  return ParsePrototype();
}
コード例 #11
0
ファイル: parser.cpp プロジェクト: reverendhomer/tupac
// external ::= 'extern' prototype
std::unique_ptr<CPrototypeAST> CParser::ParseExtern()
{
	GetNextToken(); // eating "extern"
	return ParsePrototype();
}