コード例 #1
0
ファイル: logic_expressions.c プロジェクト: swills/core
static ParseResult ParseNotExpression(const char *expr, int start, int end)
{
    if (start < end && expr[start] == '!')
    {
        ParseResult primres = ParsePrimary(expr, start + 1, end);

        if (primres.result)
        {
            Expression *res = xcalloc(1, sizeof(Expression));

            res->op = NOT;
            res->val.not.arg = primres.result;

            return (ParseResult)
            {
                res, primres.position
            };
        }
        else
        {
            return primres;
        }
    }
    else
    {
        return ParsePrimary(expr, start, end);
    }
}
コード例 #2
0
ファイル: Json.cpp プロジェクト: JackWyj/Json-Parser
Json* Json::Parser::ParsePair(){
	Json* jstring = ParsePrimary();
	if(jstring->_kind != kString) JSON_ASSERT("json of string expected");
	NextChar();
	if(ch != ':') JSON_ASSERT("expect \":\"");
	Json* value = ParsePrimary();
	Pair* pairs = new Pair(*(std::string*)(jstring->_data), value);
	return new Json(pairs);
}
コード例 #3
0
ファイル: toy.cpp プロジェクト: AlexDenisov/llvm
/// binoprhs
///   ::= ('+' primary)*
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
                                              std::unique_ptr<ExprAST> LHS) {
  // If this is a binop, find its precedence.
  while (1) {
    int TokPrec = GetTokPrecedence();

    // If this is a binop that binds at least as tightly as the current binop,
    // consume it, otherwise we are done.
    if (TokPrec < ExprPrec)
      return LHS;

    // Okay, we know this is a binop.
    int BinOp = CurTok;
    getNextToken(); // eat binop

    // Parse the primary expression after the binary operator.
    auto RHS = ParsePrimary();
    if (!RHS)
      return nullptr;

    // If BinOp binds less tightly with RHS than the operator after RHS, let
    // the pending operator take RHS as its LHS.
    int NextPrec = GetTokPrecedence();
    if (TokPrec < NextPrec) {
      RHS = ParseBinOpRHS(TokPrec + 1, std::move(RHS));
      if (!RHS)
        return nullptr;
    }

    // Merge LHS/RHS.
    LHS = helper::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
                                             std::move(RHS));
  }
}
コード例 #4
0
ファイル: expr.cpp プロジェクト: Alexis211/PIF
// binoplhs
//		::= 
//		::= primary
ExprAST *Parser::ParseBinOpLHS() {
	if (Lex.tokStr == "-" || Lex.tokStr == "@" || Lex.tokStr == "!") {
		return 0;
	} else {
		return ParsePrimary();
	}
}
コード例 #5
0
ファイル: Main.cpp プロジェクト: kpdev42/Kaleidoscope
/// binoprhs
///   ::= ('+' primary)*
static ExprAST *ParseBinOpRHS(int ExprPrec, ExprAST *LHS) {
  // If this is a binop, find its precedence.
  while (1) {
    int TokPrec = GetTokPrecedence();

    // If this is a binop that binds at least as tightly as the current binop,
    // consume it, otherwise we are done.
    if (TokPrec < ExprPrec)
      return LHS;

    // Okay, we know this is a binop.
    int BinOp = CurTok;
    getNextToken();  // eat binop

    // Parse the primary expression after the binary operator.
    ExprAST *RHS = ParsePrimary();
    if (!RHS) return 0;

    // If BinOp binds less tightly with RHS than the operator after RHS, let
    // the pending operator take RHS as its LHS.
    int NextPrec = GetTokPrecedence();
    if (TokPrec < NextPrec) {
      RHS = ParseBinOpRHS(TokPrec+1, RHS);
      if (RHS == 0) return 0;
    }

    // Merge LHS/RHS.
    LHS = new BinaryExprAST(BinOp, LHS, RHS);
  }
}
コード例 #6
0
ファイル: toy.cpp プロジェクト: AlexDenisov/llvm
/// expression
///   ::= primary binoprhs
///
static std::unique_ptr<ExprAST> ParseExpression() {
  auto LHS = ParsePrimary();
  if (!LHS)
    return nullptr;

  return ParseBinOpRHS(0, std::move(LHS));
}
コード例 #7
0
ファイル: fit__misc_c.c プロジェクト: Starlink/starlink
static NodeRef ParseTerm( char **spec, int *status )
  {
  NodeRef		node = NIL;

  node = ParsePrimary( spec, status );

  while ( (curtok == TOK_TIMES) && _ok(status) )
    {
    NextToken( spec, status );

    node = NewNode( TOK_TIMES, 0, node,
		     ParsePrimary(spec, status),
		     status );
    }

  return node;
  }
コード例 #8
0
ファイル: udf_parser.cpp プロジェクト: camellyx/peloton
/// expression
///   ::= primary binoprhs
///
std::unique_ptr<ExprAST> UDFParser::ParseExpression() {
  auto lhs = ParsePrimary();
  if (!lhs) {
    return nullptr;
  }

  return ParseBinOpRHS(0, std::move(lhs));
}
コード例 #9
0
/* expression
 * ::= primary binoprhs
 * */
static shared_ptr<ExprAST> ParseExpression() {
    auto LHS = ParsePrimary();
    if (!LHS)
        return 0;
    if (LHS->getType() == Ty_string)
        return LHS;
    return ParseBinOpRHS(1, LHS);
}
コード例 #10
0
ファイル: FAO.cpp プロジェクト: OkabeRintarou/syl
ExprAST * FAO::ParseExpression()
{
	ExprAST * lhs = ParsePrimary();
	if (lhs == nullptr){
		return nullptr;
	}

	return ParseBinOpRHS(0, lhs);
}
コード例 #11
0
ファイル: db_statement.c プロジェクト: neutered/propgcc
/* ParseLet - parse the 'LET' statement */
static void ParseLet(ParseContext *c)
{
    ParseTreeNode *lvalue;
    PVAL pv;
    lvalue = ParsePrimary(c);
    code_lvalue(c, lvalue, &pv);
    FRequire(c, '=');
    ParseRValue(c);
    (*pv.fcn)(c, PV_STORE, &pv);
    FRequire(c, T_EOL);
}
コード例 #12
0
ファイル: json_parser.cpp プロジェクト: curtisai/CS585MKII
        //create a JsonPair object while pair found
		sgdm::StackGuard<JsonValue>&& JsonParser::ParsePair(){
			sgdm::StackGuard<JsonValue> pairName(new JsonName(idString));
			getNextTok();
			if(currentTok != ':'){
				return Error("Expecting :");
			}
			else{
				getNextTok(); //eat :
				sgdm::StackGuard<JsonValue> pairValue(std::move(ParsePrimary()));
				return std::move(new JsonPair(std::move(pairName),std::move(pairValue)));
			}
		}
コード例 #13
0
ファイル: Parser.cpp プロジェクト: Arkm4n/Syntaxer
 sptr<ExprNode> Parser::ParseUnary()
 {
     if (Match(PLUS, MINUS, NOT, -1))
     {
         sptr<Token> buff = currToken;
         NextToken();
         return sptr<UnOpNode>(new UnOpNode(buff, ParseUnary()));
     }
     else
     {
         return ParsePrimary();
     }
 }
コード例 #14
0
ファイル: Json.cpp プロジェクト: JackWyj/Json-Parser
Json* Json::Parser::ParseArray(){
	NextChar();
	Array* array = new Array;
	Json* member;
	while(ch != ']'){
		BackCharIndex();
		member = ParsePrimary();
		array->push_back(member);
		NextChar();
		if(ch == ',') NextChar();
	}
	return new Json(array);
}
コード例 #15
0
ファイル: parser.cpp プロジェクト: reverendhomer/tupac
// unary
//   ::= primary
//   ::= '!' unary
std::unique_ptr<CExprAST> CParser::ParseUnary()
{
	// If current token is not an operator, it must be a primary expr
	if (!isascii(m_CurrentToken) || m_CurrentToken == '(' || m_CurrentToken == ',')
		return ParsePrimary();

	// If this is an unary operator, read it
	int opcode = m_CurrentToken;
	GetNextToken();
	auto operand = ParseUnary();
	if (operand)
		return std::make_unique<CUnaryExprAST>(opcode, std::move(operand));

	return nullptr;
}
コード例 #16
0
/* binoprhs
 * ::= ('+' primary)*
 * */
static shared_ptr<ExprAST> ParseBinOpRHS(int lasprec, shared_ptr<ExprAST> LHS) {
    while (1) {
        int curprec = getTokPrecedence();
        if (curprec < lasprec)
            return LHS;
        int op = CurTok;
        getNextToken();     //eat op
        auto RHS = ParsePrimary();
        if (!RHS) return 0;
        int nextprec = getTokPrecedence();
        if (curprec < nextprec) {
            RHS = ParseBinOpRHS(curprec + 1, RHS);
            if (!RHS) return 0;
        }
        LHS = shared_ptr<ExprAST>(new BinaryExprAST(op, LHS, RHS));
    }
}
コード例 #17
0
ファイル: json_parser.cpp プロジェクト: curtisai/CS585MKII
		//create a JsonArray object while array found
		sgdm::StackGuard<JsonValue>&& JsonParser::ParseArray(){
			if(currentTok != '['){
				return Error("Expecting [ at the beginning");
			}
			sgdm::StackGuard<JsonValue> array(new JsonArray());
			getNextTok();
			while(currentTok != ']'){
				if (currentTok == ','){
					getNextTok();
					continue;
				}
				else{
					array->push(std::move(ParsePrimary()));
				}	
			}
			getNextTok();     //eat ]
            return std::move(array);
        }
コード例 #18
0
ファイル: db_statement.c プロジェクト: neutered/propgcc
/* ParseImpliedLetOrFunctionCall - parse an implied let statement or a function call */
static void ParseImpliedLetOrFunctionCall(ParseContext *c)
{
    ParseTreeNode *expr;
    Token tkn;
    PVAL pv;
    expr = ParsePrimary(c);
    switch (tkn = GetToken(c)) {
    case '=':
        code_lvalue(c, expr, &pv);
        ParseRValue(c);
        (*pv.fcn)(c, PV_STORE, &pv);
        break;
    default:
        SaveToken(c, tkn);
        code_rvalue(c, expr);
        putcbyte(c, OP_DROP);
        break;
    }
    FRequire(c, T_EOL);
}
コード例 #19
0
ファイル: json_parser.cpp プロジェクト: curtisai/CS585MKII
        //top level parse function
        sgdm::StackGuard<JsonValue>&& JsonParser::ParsePrimary(){
        	switch(currentTok){
        		case tok_endl:
        		    return std::move(Error("primary fail"));
        		case tok_identifier:
        		    return std::move(ParseName());
        		case tok_integer:
        		    return std::move(ParseInteger());
        		case tok_double:
        		    return std::move(ParseDouble());
        		case '[':
        			return std::move(ParseArray(alloc));
        		case '{':
        		    return std::move(ParseObject(alloc));
        		default:
        		    return std::move(Error("unknown token found near place" + std::to_string(indexCount)));
		
		}

		sgdm::StackGuard<JsonValue>&& JsonParser::Parse(){
			getNextTok();
			return std::move(ParsePrimary(alloc));
		}
コード例 #20
0
ファイル: udf_parser.cpp プロジェクト: camellyx/peloton
/// binoprhs
///   ::= ('+' primary)*
std::unique_ptr<ExprAST> UDFParser::ParseBinOpRHS(
    int expr_prec, std::unique_ptr<ExprAST> lhs) {
  // If this is a binop, find its precedence.
  while (true) {
    int tok_prec = GetTokPrecedence();

    // If this is a binop that binds at least as tightly as the current binop,
    // consume it, otherwise we are done.
    if (tok_prec < expr_prec) {
      return lhs;
    }

    // Okay, we know this is a binop.
    int bin_op = cur_tok_;
    GetNextToken();  // eat binop

    // Parse the primary expression after the binary operator.
    auto rhs = ParsePrimary();
    if (!rhs) {
      return nullptr;
    }

    // If BinOp binds less tightly with rhs than the operator after rhs, let
    // the pending operator take rhs as its lhs.
    int next_prec = GetTokPrecedence();
    if (tok_prec < next_prec) {
      rhs = ParseBinOpRHS(tok_prec + 1, std::move(rhs));
      if (!rhs) {
        return nullptr;
      }
    }

    // Merge lhs/rhs.
    lhs = llvm::make_unique<BinaryExprAST>(bin_op, std::move(lhs),
                                           std::move(rhs));
  }
}
コード例 #21
0
ファイル: FAO.cpp プロジェクト: OkabeRintarou/syl
ExprAST * FAO::ParseBinOpRHS(int Expc, ExprAST * lhs)
{
	// If this is a binary operator,find its precedence
	while (true){
		int TokPrec = GetPrecedence();
		// If this is a binary operator,find its precedence at least as tightly as the current binary operator
		// consume it,otherwise we are done.
		if (TokPrec < Expc){
			return lhs;
		}

		// Okay,we know this is binary operator
		char BinOp = cur_token_.GetOperation();
		Advance(); // eat binary operator

		// Parse the primary expression after the binary operator
		ExprAST * rhs = ParsePrimary();
		if (rhs == nullptr){
			return nullptr;
		}

		// If binary operator less tightly with rhs than the operator after rhs,let
		// the pending operator than rhs as its lhs
		int NextPrec = GetPrecedence();
		if (TokPrec < NextPrec){
			rhs = ParseBinOpRHS(TokPrec + 1, rhs);
			if (rhs == nullptr){
				return nullptr;
			}
		}
		
		// Merge lhs/rhs
		lhs = new BinaryOpExpr(BinOp, lhs, rhs);
	}
	return lhs;
}
コード例 #22
0
ファイル: parser.cpp プロジェクト: ornata/llvm-stuff
/*
* Handle the rhs of a binary operation, where
* binoprhs ::= (binop primary)*
*/
static std::unique_ptr<ExprAST> ParseBinOpRHS(int minExprPrec,
                                              std::unique_ptr<ExprAST> lhs)
{
    while (1) {
        int tokPrec = GetTokPrecedence();

        // token's precedence is too low to do anything with so we're done
        if (tokPrec < minExprPrec) {
            return lhs;
        }

        // otherwise, precedence it high enough so we should handle the binop
        int binOp = CurTok;
        getNextToken(); // advance past the binop

        // parse the primary expression after the operator
        auto rhs = ParsePrimary();

        if (!rhs) {
            return nullptr;
        }

        // determine the direction of associativity
        int nextPrec = GetTokPrecedence();

        if (tokPrec < nextPrec) {
            rhs = ParseBinOpRHS(tokPrec + 1, std::move(rhs));
            if (!rhs) {
                return nullptr;
            }
        }

        // merge the lhs and rhs
        lhs = llvm::make_unique<BinaryExprAST>(binOp, std::move(lhs), std::move(rhs));
    }
}
コード例 #23
0
ファイル: Main.cpp プロジェクト: kpdev42/Kaleidoscope
/// expression
///   ::= primary binoprhs
///
static ExprAST *ParseExpression() {
  ExprAST *LHS = ParsePrimary();
  if (!LHS) return 0;

  return ParseBinOpRHS(0, LHS);
}
コード例 #24
0
ファイル: udf_parser.cpp プロジェクト: camellyx/peloton
std::unique_ptr<ExprAST> UDFParser::ParseReturn() {
  GetNextToken();  // eat the return
  return ParsePrimary();
}