Ejemplo n.º 1
0
/// 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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
// 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));
}
Ejemplo n.º 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;
}
Ejemplo n.º 5
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;
    }
}
Ejemplo n.º 6
0
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));
	}
}
Ejemplo n.º 7
0
/// external ::= 'extern' prototype
static shared_ptr<PrototypeAST> ParseExtern() {
    getNextToken();  // eat extern.
    return ParsePrototype();
}
Ejemplo n.º 8
0
/// external ::= 'extern' prototype
static PrototypeAST *ParseExtern() {
  getNextToken();  // eat extern.
  return ParsePrototype();
}
Ejemplo n.º 9
0
/*
* Handle external prototypes, where
* external ::= 'extern' prototype
*/
static std::unique_ptr<PrototypeAST> ParseExtern()
{
    getNextToken(); // advance past 'extern'
    return ParsePrototype();
}
Ejemplo n.º 10
0
/// external ::= 'extern' prototype
static std::unique_ptr<PrototypeAST> ParseExtern() {
  getNextToken(); // eat extern.
  return ParsePrototype();
}
Ejemplo n.º 11
0
// external ::= 'extern' prototype
std::unique_ptr<CPrototypeAST> CParser::ParseExtern()
{
	GetNextToken(); // eating "extern"
	return ParsePrototype();
}