当前位置: 首页>>代码示例>>C++>>正文


C++ parseExpression函数代码示例

本文整理汇总了C++中parseExpression函数的典型用法代码示例。如果您正苦于以下问题:C++ parseExpression函数的具体用法?C++ parseExpression怎么用?C++ parseExpression使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parseExpression函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parseExpression

/***************************************************************
* Function: CodeParser::parseParamExpr()
* Purpose : Parse the XML code of a parameterized expression
* Initial : Maxime Chevalier-Boisvert on November 7, 2008
****************************************************************
Revisions and bug fixes:
*/
Expression* CodeParser::parseParamExpr(const XML::Element* pElement)
{
	// Parse the symbol expression
	Expression* pExpr = parseExpression(pElement->getChildElement(0));

	// Compute the number of arguments
	size_t numArgs = pElement->getNumChildren() - 1;

	// Declare a vector for the arguments
	ParamExpr::ExprVector arguments;

	// For each child element
	for (size_t i = 0; i < numArgs; ++i)
	{
		// Parse this argument
		arguments.push_back(parseExpression(pElement->getChildElement(i + 1)));
	}

	// Create and return the new parameterized expression
	return new ParamExpr(
		pExpr,
		arguments
	);
}
开发者ID:debashish1711,项目名称:mcvm,代码行数:31,代码来源:parser.cpp

示例2: match

SymbolTableEntry* Parser::parseVariablePrime(SymbolTableEntry* prevEntry){
	if(isNext(tc_LBRACKET)){
		match(tc_LBRACKET);
		parseExpression();
		match(tc_RBRACKET);
		if(m_parserError){
			TokenCode synch[] = {tc_RBRACKET, tc_END, tc_ASSIGNOP, tc_MULOP, tc_RELOP, tc_THEN, tc_DO, tc_COMMA, tc_RPAREN, tc_NONE};
			recover(synch);
//			if(isNext(tc_RBRACKET)){
//				match(tc_RBRACKET);
//			}
		}
	}
	return prevEntry;
}
开发者ID:nicolai490,项目名称:---endur,代码行数:15,代码来源:parser.cpp

示例3: consumeToken

/*!
 *  rule ::= 'id' ( '::=' | '->' ) expression
 */
RuleNode* Parser::parseRule()
{
    std::string name = token_value_;
    consumeToken();

    if (token_ != Lexer::Token::coloncolonequal &&
        token_ != Lexer::Token::minusgreater) {
        return static_cast<RuleNode*>(errorNode("missing terminating character \"::=\" or\" ->\""));
    }
    consumeToken();

    Node* node = parseExpression();

    return new RuleNode(name, node);
}
开发者ID:marcioAlmada,项目名称:railroad-diagram-generator,代码行数:18,代码来源:parser.cpp

示例4: if

	shared_ptr<Expression> Parser::parseFactor()
	{
		if (it->tag == IDENT || it->tag == INT || it->tag == FLOAT)
		{
			auto exp = make_shared<Expression>();
			exp->value = *it;
			return exp;
		}
		else if (it->tag == OpenBracket)
		{
			auto exp = parseExpression();
			match(CloseBracket);
			return exp;
		}
	}
开发者ID:caiyulun,项目名称:compiler2014,代码行数:15,代码来源:parser.cpp

示例5: parseExpressionStatement

Symbol parseExpressionStatement(CharacterSource* source)
{
    CharacterSource s = *source;
    Symbol expression = parseExpression(&s);
    if (!expression.valid())
        return Symbol();
    Span span;
    if (!Space::parseCharacter(&s, ';', &span))
        return Symbol();
    *source = s;
    if (expression.atom() != atomFunctionCall)
        source->location().throwError("Statement has no effect");
    return Symbol(atomExpressionStatement, expression,
        newSpan(spanOf(expression) + span));
}
开发者ID:mstram,项目名称:reenigne,代码行数:15,代码来源:statement.cpp

示例6: parseArrayDefineNode

void parseArrayDefineNode(std::string&result,ArrayDefineNode*seg){
	if(seg == NULL){
		return;
	}
	char numStr[N_INT_CHAR];
	sprintf(numStr, "%d", ++lineno);

	result+="{\"name\":\"" + std::string(numStr) + ": array define\",\"children\":[";
	result+="{\"name\":\"" + std::string(seg->type) + "\"},";
	result+="{\"name\":\"" + std::string(seg->name) + "\"},";
	result += "{\"name\":\"nElement\",\"children\":[{\"name\":\"";
	parseExpression(result, seg->exp);
	result += "\"}]}";
	result+="]}";
}
开发者ID:abucraft,项目名称:OALanguage,代码行数:15,代码来源:parser.cpp

示例7: parseFunctionCall

static bool parseFunctionCall(MemoryStack* stack, LexerCarriage* carriage, Array<SyntaxError>* errors, ASTNode* result)
{
    LexerCarriage tmpCarriage = *carriage;

    if (tmpCarriage.topToken.type == TOK_IDENTIFIER)
    {
        Token identifier = tmpCarriage.topToken;
        parseNextToken(&tmpCarriage);

        if (tmpCarriage.topToken.type == TOK_OPEN_BRACKET)
        {
            parseNextToken(&tmpCarriage);

            result->nodeType = AST_FUNCTION_CALL;
            result->functionCall.lineNumber = carriage->currentLineNumber;
            result->functionCall.identifier = identifier.identifierValue;
            result->functionCall.arguments = { };

            if (tmpCarriage.topToken.type != TOK_CLOSE_BRACKET)
            {
                ASTNode argument;
                do {
                    if (parseExpression(stack, &tmpCarriage, errors, &argument))
                    {
                        *pushElement(&result->functionCall.arguments, stack) = argument;
    
                        if (tmpCarriage.topToken.type == TOK_COMMA)
                            parseNextToken(&tmpCarriage);
                        else
                            break;
                    }
                    else
                    {
                        pushBack(errors, SyntaxError{ SET_EXPRESSION_EXPECTED });
                        break;
                    }
                } while (true);
            }

            expectAndEat(&tmpCarriage, TOK_CLOSE_BRACKET, errors);
            *carriage = tmpCarriage;

            return true;
        }
    }

    return false;
}
开发者ID:DRDivider,项目名称:TWIScript,代码行数:48,代码来源:Parser.cpp

示例8: ensureKeyword

IfNode* Parser::parseIf() {
    uint32_t token = _currentTokenIndex;
    ensureKeyword("if");
    ensureToken(tLPAREN);
    AstNode* ifExpr = parseExpression();
    ensureToken(tRPAREN);

    BlockNode* thenBlock = parseBlock(true);
    BlockNode* elseBlock = 0;
    if (currentTokenValue() == "else") {
        consumeToken();
        elseBlock = parseBlock(true);
    }

    return new IfNode(token, ifExpr, thenBlock, elseBlock);
}
开发者ID:nvmd,项目名称:spbau-mathvm,代码行数:16,代码来源:parser.cpp

示例9: ParserSyntaxException

/*** Parse a return statement ***/
Return* Parser::parseReturn()
{
	if(!hasTokens() || peekToken().getType() != T_RETURN)
		throw ParserSyntaxException(getToken(), "Expected \"return\" command!");
	Token tok = getToken();

	std::auto_ptr<Return> ret(new Return());
	ret->setLineNumber(tok.getLineNumber());
	ret->setColumnNumber(tok.getColumnNumber());

	if(!hasTokens() || peekToken().getType() == T_EOL)
		return ret.release();
	std::auto_ptr<Object> expr(parseExpression());
	ret->setExpression(expr.release());
	return ret.release();
}
开发者ID:denrusio,项目名称:vak-opensource,代码行数:17,代码来源:parser.cpp

示例10: main

int main() {
   TTable mujTable;
   table = &mujTable;
   tableInit(table);

   tableInsertFunction(table, strCreateString("fce"));
   functionInsertVar(table->lastAddedFunc, strCreateString("x"));
   functionInsertVar(table->lastAddedFunc, strCreateString("y"));
   functionInsertVar(table->lastAddedFunc, strCreateString("z"));

   printf("\nJedna funkce: \n");
   tablePrintOrder(*table);
   printf("\n----------------------------\n");


//tiskniPrecTab();
   FILE *f = fopen("testy/test-expr2.txt","r");
   setSourceFile(f);
   strInit(&attr);
   listInit(&table->lastAddedFunc->tmpVar);

   int err = EOK;
   TVar *x = NULL;
   int test = 1;
   token = 1;

   while(token != END_OF_FILE) {
      token = getNextToken(&attr);
      x = NULL;
      err = parseExpression(table, &x);
      printf("Test %d skoncil s chybou: %d a vysledkem: %d \n", test,err, (int)x);
      test++;

      while (token != END_OF_FILE && token != L_SEMICOLON) {
         token = getNextToken(&attr);
      }
   }
   tiskniList(&table->lastAddedFunc->instructions);

   listDataDelete(&table->lastAddedFunc->tmpVar);
   listDispose(&table->lastAddedFunc->tmpVar);

   fclose(f);
   tableClear(table);
   strFree(&attr);
   return EXIT_SUCCESS;
}
开发者ID:fkolacek,项目名称:FIT-VUT,代码行数:47,代码来源:test-expression.c

示例11: Error

// <parenexpr>          ::= '(' <expression> ')'
IAstExpression *Parser::parseParenExpression() {
    if (_curTokenType != '(') {
        return Error("Expected '('.");
    }
    next(); // eat '('
    
    IAstExpression *expr = parseExpression();
    if (expr == nullptr) {
        return nullptr;
    }

    if (_curTokenType != ')') {
        return Error("Expected ')'.");
    }
    next(); // eat ')'
    return expr;
}
开发者ID:traplol,项目名称:demiurge-lang,代码行数:18,代码来源:Parser.cpp

示例12: parsePrefixUnaryExpr

// <primary>            ::= <parenexpr>
//                      |   <identifier>
//                      |   <string>
//                      |   <bool>
//                      |   <number>
IAstExpression *Parser::parsePrimary() {
    if (_curToken->IsUnaryOperator())
    {
        IAstExpression *unary = parsePrefixUnaryExpr();
        if (unary != nullptr) {
            return unary;
        }
    }
    switch (_curTokenType) {
    default: return nullptr;
    case '(': return parseParenExpression();
    case ';': next(); return parseExpression();
    case tok_identifier: return parseIdentifierExpression();
    case tok_string: return parseStringExpression();
    case tok_bool: return parseBooleanExpression();
    case tok_number: return parseNumberExpression();
    }
}
开发者ID:traplol,项目名称:demiurge-lang,代码行数:23,代码来源:Parser.cpp

示例13: parseAssignment

static PSmmAstNode parseAssignment(PSmmParser parser, PSmmAstNode lval) {
	PSmmToken eqToken = parser->curToken;
	getNextToken(parser);
	PSmmAstNode val = parseExpression(parser);
	if (val == &errorNode) {
		findToken(parser, ';');
		return &errorNode;
	}

	if (val->kind == nkSmmParamDefinition) return val;

	PSmmAstNode assignment = smmNewAstNode(nkSmmAssignment, parser->a);
	assignment->left = lval;
	assignment->right = val;
	assignment->type = lval->type;
	assignment->token = eqToken;
	return assignment;
}
开发者ID:igor84,项目名称:summus,代码行数:18,代码来源:smmparser.c

示例14: parseIncrementDecrementStatement

Symbol parseIncrementDecrementStatement(CharacterSource* source)
{
    Span span;
    Symbol function;
    if (Space::parseOperator(source, increment, &span))
        function = Symbol(atomIncrement);
    else if (Space::parseOperator(source, decrement, &span))
        function = Symbol(atomDecrement);
    else
        return Symbol();
    CharacterSource s = *source;
    Symbol lValue = parseExpression(&s);
    *source = s;
    Span span2;
    Space::assertCharacter(source, ';', &span2);
    return Symbol(atomFunctionCall, function, SymbolArray(lValue),
        newSpan(span + span2));
}
开发者ID:mstram,项目名称:reenigne,代码行数:18,代码来源:statement.cpp

示例15: parseVariablePrime

void Parser::parseStatementPrime(SymbolTableEntry* prevEntry){
	if(isNext(tc_LBRACKET) || isNext(tc_ASSIGNOP)){
		SymbolTableEntry* var = parseVariablePrime(prevEntry);
		match(tc_ASSIGNOP);
		if(m_parserError){
			TokenCode synch[] = {tc_ID, tc_NUMBER, tc_LPAREN, tc_NOT, tc_ADDOP, tc_NONE};
			recover(synch);
//			if(isNext(tc_ASSIGNOP)){
//				match(tc_ASSIGNOP);
//			}
		}
		SymbolTableEntry* exp = parseExpression();
		m_code->generate(cd_ASSIGN, exp, NULL, var);
	}
	else{
		parseProcedureStatementPrime(prevEntry);
	}
}
开发者ID:nicolai490,项目名称:---endur,代码行数:18,代码来源:parser.cpp


注:本文中的parseExpression函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。