本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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
//.........这里部分代码省略.........