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


C++ Token::GetTokenType方法代码示例

本文整理汇总了C++中Token::GetTokenType方法的典型用法代码示例。如果您正苦于以下问题:C++ Token::GetTokenType方法的具体用法?C++ Token::GetTokenType怎么用?C++ Token::GetTokenType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Token的用法示例。


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

示例1: CoutStatementNode

CoutStatementNode * Parser::Cout(){
	CoutStatementNode * coutnode = new CoutStatementNode();
	Match(COUT_TOKEN);
	Match(INSERTION_TOKEN);
	ExpressionNode * expr = Expression();
	coutnode->AddCnode(expr);
	while(true){	
		Token next = scan->PeekNextToken();
		if(next.GetTokenType() == INSERTION_TOKEN){
			Match(next.GetTokenType());
			Token nNext = scan->PeekNextToken();
			if(nNext.GetTokenType() == ENDL_TOKEN){
				Match(ENDL_TOKEN);
				coutnode->AddCnode(NULL);
			}
			else{
				ExpressionNode * nexpr = Expression();
				coutnode->AddCnode(nexpr);
			}
		}
		else{
			if(next.GetTokenType() == ENDL_TOKEN){
				Match(ENDL_TOKEN);
				coutnode->AddCnode(NULL);
			}
			Match(SEMICOLIN_TOKEN);
			break;
		}
	}
	MSG("Creating a CoutStatementNode.");
	return coutnode;
}
开发者ID:sstephens,项目名称:sstephens1,代码行数:32,代码来源:Parser.cpp

示例2: Match

Token Parser::Match(TokenType expectedType){
	Token curtoken = scan->GetNextToken();
	//cout << curtoken << endl;
	if(curtoken.GetTokenType() != expectedType)
	{
		cerr << "Error in the Parse::Match.\n";
		cerr << "Expected token type "<< gTokenTypeNames[expectedType] << ", but got type " << curtoken.GetTokenTypeName() << endl;
		exit(1);
	}
	MSG("\tSuccessfully matched token type: " << curtoken.GetTokenTypeName() << ". Lexeme: \"" << curtoken.GetLexeme() << "\"");
	return curtoken;
}
开发者ID:sstephens,项目名称:sstephens1,代码行数:12,代码来源:Parser.cpp

示例3: Expression

IfStatementNode * Parser::If(){
	g_maybe_upscope = true;
	Match(IF_TOKEN);
	Match(LPAREN_TOKEN);
	ExpressionNode * exp = Expression();
	Match(RPAREN_TOKEN);

	StatementGroupNode * stategroup;
	StatementGroupNode * stategroupelse;
	Token tt = scan->PeekNextToken();
	if(tt.GetTokenType() == LCURLY_TOKEN){
		Match(LCURLY_TOKEN);
		stategroup = StatementGroup();
		Match(RCURLY_TOKEN);
	}
	else{
		stategroup = StatementGroup();
	}

	TokenType next = scan->PeekNextToken().GetTokenType();
	if(next == ELSE_TOKEN)
	{
		Match(next);
		next = scan->PeekNextToken().GetTokenType();
		if(next == LCURLY_TOKEN){
			Match(LCURLY_TOKEN);
			stategroupelse = StatementGroup();
			Match(RCURLY_TOKEN);
		}
		else{
			stategroupelse = StatementGroup();
		}

	}
	else{
		stategroupelse = NULL;
	}
	IfStatementNode * ifs = new IfStatementNode(exp, stategroup, stategroupelse);
	g_maybe_upscope = false;
	g_varname.clear();
	return ifs;
}
开发者ID:sstephens,项目名称:sstephens1,代码行数:42,代码来源:Parser.cpp

示例4: if

vector<Token*>* CoreEvaluator::ShuntingOperations(vector<Token>* toUnSort)
{
    if (toUnSort == NULL) throw new exception();

    // vector
    vector<Token*>* SortedVector = new vector<Token*>();

    // queue
    queue<Token*>* toQueue = new queue<Token*>();

    // stack
    stack<Token*>* toStack = new stack<Token*>();

    // temp token
    Token* tempToken;

    // iterating token by token
    for (int i=0; i < toUnSort->size(); i++)
    {
        // 1 - reading at i
        tempToken = &toUnSort->at(i);

        // 2 - int, real or negative values
        if (isNumber(tempToken))
        {
            toQueue->push(tempToken);
        }

        // 4 - for log(v,b) and coma ERROR checking
        else if (tempToken->GetTokenType() ==  Comma) // exa: 3,4
        {


            if (toStack->empty())
            {
                cout << "Invalid expression entered." << endl;
								isValid = false;
                while (!toQueue->empty())
                {
                    toQueue->pop(); // cleaning the queue before printing the error
                }
                break;
            }

            Token* tempOpt = toStack->top();

            if (tempOpt->GetTokenType() == OpenPar) // exa: sin(3,4)
            {
                toStack->pop(); // getting the OpenPar out

                if (!toStack->empty())
                {
                    tempOpt = toStack->top(); // update top position
                }
                else
                {
                    cout << "Invalid expression entered." << endl;
										isValid = false;
                    while (!toQueue->empty())
                    {
                        toQueue->pop(); // cleaning the queue before printing the error
                    }
                    break;
                }

                if (tempOpt->GetTokenType() == sinFunc || tempOpt->GetTokenType() == cosFunc || tempOpt->GetTokenType() == tanFunc || tempOpt->GetTokenType() == PowerFunc || tempOpt->GetTokenType() == FactFunc || tempOpt->GetTokenType() == secFunc || tempOpt->GetTokenType() == cscFunc || tempOpt->GetTokenType() == cotFunc || tempOpt->GetTokenType() == lnFunc)
                {
                    cout << "Invalid expression entered." << endl;
										isValid = false;
                    while (!toQueue->empty())
                    {
                        toQueue->pop(); // cleaning the queue before printing the error
                    }
                    while (!toStack->empty())
                    {
                        toStack->pop(); // cleaning the queue before printing the error
                    }
                    break;
                }
                else // it is log
                {
                    Token* parth = new Token(OpenPar,"(");
                    toStack->push(parth); // adding the OpenPar back to stack
                    // adding and erassing the Comma
                    toStack->push(tempToken);
                    toStack->pop();
                }
            }
            else
            {
                // adding and erassing the Comma
                toStack->push(tempToken);
                toStack->pop();
            }
        }

        // 5 - an operator +,-,*,/,power ^, sin, cos, tan, factorial, log, root
        else if (isOperator(tempToken))
        {
            // if the stack is not empty
//.........这里部分代码省略.........
开发者ID:yotoo2920,项目名称:Expression_Evaluator,代码行数:101,代码来源:CoreEvaluator.cpp


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