本文整理汇总了C++中Token::TokenStr方法的典型用法代码示例。如果您正苦于以下问题:C++ Token::TokenStr方法的具体用法?C++ Token::TokenStr怎么用?C++ Token::TokenStr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::TokenStr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ENum
Expression *Parser::ParseAExpr() {
Token* tk = lexer_->GetToken();
lexer_->Advance();
switch(tk->type()) {
case Token::INT:
return new ENum(tk, atoi(tk->TokenStr().c_str()));
case Token::ID:
return new EVar(tk, tk->TokenStr());
case Token::PACK: {
Advance(Token::LBRACE);
Token* left = lexer_->GetToken();
if (left->type() != Token::INT) {
throw ParseException(left, "expect a INT here");
}
int tag = atoi(left->TokenStr().c_str());
lexer_->Advance();
Advance(Token::COMMA);
Token* right = lexer_->GetToken();
if (right->type() != Token::INT) {
throw ParseException(right, "expect a INT here");
}
int arity = atoi(right->TokenStr().c_str());
lexer_->Advance();
Advance(Token::RBRACE);
return new EConstructor(tk, tag, arity);
}
case Token::LPAREN: {
lexer_->Advance();
Expression* result = ParseExpr();
Advance(Token::RPAREN);
return result;
}
default:
throw ParseException(tk, "Should Not Get Here");
}
}
示例2: EApplication
Expression *Parser::ParseCmpExpr() {
// PlusExpr [ Op PlusExpr ] *
Expression* current = ParsePlusExpr();
while (IsCmpOperator(lexer_->GetToken()->type())) {
Token* token = lexer_->GetToken();
lexer_->Advance();
Expression * right = ParsePlusExpr();
current = new EApplication(token,
new EApplication(token,
new EVar(token, token->TokenStr()),
current),
right);
}
return current;
}
示例3: ParseException
SuperCombinatorDef *Parser::ParseSCDef() {
if (lexer_->GetToken()->type() != Token::ID) {
throw ParseException(lexer_->GetToken(), "expected a function name");
}
Token* token = lexer_->GetToken();
lexer_->Advance();
SuperCombinatorDef::Symbol name = token->TokenStr();
SuperCombinatorDef::SymbolList vars;
while (lexer_->GetToken()->type() == Token::ID) {
vars.push_back(lexer_->GetToken()->TokenStr());
lexer_->Advance();
}
Advance(Token::ASSIGN);
Expression* body = ParseExpr();
return new SuperCombinatorDef(token, name, vars, body);
}