本文整理汇总了C++中TokenList类的典型用法代码示例。如果您正苦于以下问题:C++ TokenList类的具体用法?C++ TokenList怎么用?C++ TokenList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TokenList类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: removeBlockComments
//Remove all block comments from the tokenList including /* and */ markers
//Returns the number of block comments removed (where each pair of /* and */ count as one comment)
int removeBlockComments(TokenList &tokenList) {
//this funtion deletes the block comments in the tokenlist
int count = 0;
bool deleted = false;
Token* temp, *destroy;
temp = tokenList.getFirst();
while (temp) {
//loop check if list is empty
deleted = false;
if (temp->getStringRep() == "/*") {
//upon finding a block entry comment you keep deleating tokens till you find the exit token
count++;
while (!deleted) {
destroy = temp;
temp = temp->getNext();
tokenList.deleteToken(destroy);
if (temp->getStringRep() == "*/") {
//once the exit block token is found stop delete looping and continue searching through the list for block entry symbols
destroy = temp;
temp = temp->getNext();
deleted = true;
tokenList.deleteToken(destroy);
}
}
}
else {
temp = temp->getNext();
}
}
return count;
}
开发者ID:TheChyz,项目名称:Parser,代码行数:33,代码来源:assignment2.cpp
示例2: TokenList
unsigned int Bayes::GetTokenCount(const string& token, BayesTokenType type)
{
TokenList list = type == Spam ? spam : type == Ham ? ham : TokenList();
if(list.count(token) == 0)
return 0;
return list[token];
}
开发者ID:harshulj,项目名称:SpamFilter,代码行数:7,代码来源:Bayes.cpp
示例3: m_tokenizer
Expression ExpressionBuilder::Build(std::string expression) {
TokenList tokens = m_tokenizer(expression);
TokenList postfix = m_converter(tokens);
std::stack<ExpressionNode*> nodeStk;
auto it = postfix.begin();
nodeStk.push(m_nodeBuilder.NewExpressionNode(*it));
while (++it != postfix.end()) {
ExpressionNode* node = m_nodeBuilder.NewExpressionNode(*it);
switch (node->NumChildren()) {
case 0:
nodeStk.push(node);
break;
case 1:
static_cast<OperatorNode*>(node)->SetChild(nodeStk.top());
nodeStk.pop();
nodeStk.push(node);
break;
case 2:
static_cast<OperatorNode*>(node)->SetChild(nodeStk.top(), 1);
nodeStk.pop();
static_cast<OperatorNode*>(node)->SetChild(nodeStk.top(), 0);
nodeStk.pop();
nodeStk.push(node);
break;
}
}
return{ nodeStk.top(), m_nodeBuilder.GetVariableMap() };
}
开发者ID:fireland15,项目名称:lindenmayer-system,代码行数:35,代码来源:expression-builder.cpp
示例4: skipWhitespace
Declaration* CssParser::parseDeclaration () {
Declaration* declaration = NULL;
TokenList property;
if (!parseProperty(&property))
return NULL;
skipWhitespace();
declaration = new Declaration(property.toString());
if (tokenizer->getTokenType() != Token::COLON) {
throw new ParseException(tokenizer->getToken()->str,
"colon following property(':')");
}
tokenizer->readNextToken();
skipWhitespace();
TokenList* value = parseValue();
if (value == NULL) {
throw new ParseException(tokenizer->getToken()->str,
"value for property");
}
declaration->setValue(value);
return declaration;
}
开发者ID:smalyshev,项目名称:clessc,代码行数:26,代码来源:CssParser.cpp
示例5: removeComments
//Removes all comments from the tokenList including the -- marker
//Returns the number of comments removed
int removeComments(TokenList &tokenList)
{
int count = 0;
Token* current = tokenList.getFirst();//initialized current to the first token
while (current) //this loop run till end of the list
{
if (current->getStringRep() == "--")
{
count++; //count comment to remove
Token* remove_first = current;//make a pointer to remove '--'
if (current->getNext() != NULL)
{
Token* remove_second = current->getNext();
//check comment on the last line
current = remove_second->getNext();
tokenList.deleteToken(remove_first);
tokenList.deleteToken(remove_second);
}
else
{
delete current;
}
}
else
{
current = current->getNext();
}
}
return count; //Returns the number of comments removed
}
开发者ID:liuyal,项目名称:Cpp-Projects,代码行数:36,代码来源:parserClasses.cpp
示例6: removeTokensOfType
//remove token of given type
int removeTokensOfType(TokenList &tokenList, tokenType type)
{
int count = 0;
Token* current = tokenList.getFirst();//initialized current to the first token
while (current) //this loop run till end of the list
{
if (current->getTokenType() == type)
{
count++;
Token* remove_first = current;
if (current->getNext() != NULL)
{
tokenList.deleteToken(remove_first);
}
else
{
delete current;
}
}
else
{
current = current->getNext();
}
}
return count;
}
开发者ID:liuyal,项目名称:Cpp-Projects,代码行数:31,代码来源:parserClasses.cpp
示例7: Reset
//////////////////////////////////////////////////////////////////////////
//
// Class VMemory
//
void ETCompiler::VMemory::LoadCode( const std::string& code )
{
Reset();
std::string line;
std::string::const_iterator iter = code.begin();
while ( iter != code.end() )
{
line += *iter;
if ( *iter == '\n' )
{
//TranslateLine(line);
TokenList tokList = str2Tok( line );
Instruction ins;
for ( auto iter = tokList.begin(); iter != tokList.end(); iter++ )
{
ins.m_elements.push_back( *iter );
}
m_instructions.push_back( ins );
line = "";
}
iter++;
}
}
开发者ID:daiwx,项目名称:UltraDemo,代码行数:35,代码来源:ETMachine.cpp
示例8: findAllConditionalExpressions
//Creates a new TokenList, and returns a pointer to this list
//Searches for all conditional expressions in tokenList and appends them to the new list
//Format is as follows:
//Each token that is part of a condtional expression is appended sequentially
//At the end of a conditional expression a newline character is appened
//Example: if (a = true) then
//Your list should include "(", "a", "=", "true", ")" and "\n"
//tokenList is NOT modified
TokenList* findAllConditionalExpressions(const TokenList &tokenList)
{
TokenList* conditionalExpressionTokenList = new TokenList();
Token* t = tokenList.getFirst();
while (t!= nullptr && t->getNext()!= nullptr)
{
if (t!= nullptr && (t->getStringRep() == "if" || t->getStringRep() == "elsif") && t->getPrev()->getStringRep()!="end" && !t->isComment()&& t->getNext()!= nullptr)
{
t = t->getNext();
while (t!= nullptr && !(t->getStringRep() == "then" && !t->isComment()) && t->getNext()!= nullptr){
conditionalExpressionTokenList->append(t->getStringRep());
t = t->getNext();}
conditionalExpressionTokenList ->append("\n");
}
if (t!= nullptr && t->getStringRep() == "when" && !t->isComment() && t->getNext()!= nullptr)
{
t = t->getNext();
while (t!=nullptr && !(t->getStringRep() == "else" && !t->isComment())&& t->getNext()!= nullptr)
{
conditionalExpressionTokenList->append(t->getStringRep());
t = t->getNext();}
conditionalExpressionTokenList ->append("\n");
}
t = t->getNext();}
return conditionalExpressionTokenList;
}
开发者ID:arleneF,项目名称:VHDLChecker,代码行数:34,代码来源:parserClasses.cpp
示例9: error_type
//check for mismatch type
int error_type(const TokenList &tokenList, const TokenList &tokenList2)
{
int mis_type = 0;
Token *current = new Token;
Token *numbers = new Token;
Token *temp = new Token;
current = tokenList.getFirst();
numbers = tokenList2.getFirst();
while (current && numbers)
{
// find a operator and look at surrounding tokens
if (current->getTokenType() == T_Identifier && current->getTokenDetails() != NULL &&
current->getNext()->getTokenType() == T_Operator && current->getNext()->getNext()->getTokenDetails() != NULL &&
current->getNext()->getNext()->getTokenType() != T_Literal)
{
string temp_typeA = current->getTokenDetails()->type;
string temp_typeB = current->getNext()->getNext()->getTokenDetails()->type;
//if details of type are not the same
if (temp_typeA != temp_typeB)
{
cout << "ERROR mismatch type on line: " << numbers->getStringRep() << endl;
mis_type++;
}
}
numbers = numbers->getNext();
current = current->getNext();
}
return mis_type;
}
开发者ID:liuyal,项目名称:Cpp-Projects,代码行数:33,代码来源:project.cpp
示例10: GetSection
string GetSection(const string& File, const string& Sec)
{
istringstream is(File);
ASSERT(is);
TokenList TL;
bool Found = false;
do {
is >> TL;
if (!TL.empty()) {
TokenList TL2(TL[0],"=\\");
Found = TL2[0] == Sec;
}
} while(!Found && is);
if (Found) { // Get the rest of the lines in the section
while (*(TL.rbegin()->rbegin()) == '\\') {
TokenList TL2;
is >> TL2;
TL += TL2;
}
}
return TL.getString();
}
开发者ID:jnafziger,项目名称:pdft-nwchem,代码行数:25,代码来源:convmake.cpp
示例11: interpolate
void ValueProcessor::interpolate(std::string &str,
const ValueScope &scope) const {
size_t start, end = 0;
string key, value;
const TokenList *var;
TokenList variable;
while ((start = str.find("@{", end)) != string::npos &&
(end = str.find("}", start)) != string::npos) {
key = "@";
key.append(str.substr(start + 2, end - (start + 2)));
var = scope.getVariable(key);
if (var != NULL) {
variable = *var;
processValue(variable, scope);
// Remove quotes off strings.
if (variable.size() == 1 && variable.front().type == Token::STRING) {
variable.front().removeQuotes();
}
value = variable.toString();
str.replace(start, (end + 1) - start, value);
end = start + value.length();
}
}
}
开发者ID:BramvdKroef,项目名称:clessc,代码行数:31,代码来源:ValueProcessor.cpp
示例12: processDeclaration
bool UnprocessedStatement::processDeclaration (Declaration* declaration) {
TokenList property;
Token keyword;
#ifdef WITH_LIBGLOG
VLOG(3) << "Declaration";
#endif
getValue(declaration->getValue());
if (declaration->getValue().empty() ||
declaration->getValue().front().type != Token::COLON) {
return NULL;
}
declaration->getValue().pop_front();
getProperty(property);
keyword = property.front();
keyword.assign(property.toString());
declaration->setProperty(keyword);
return true;
}
开发者ID:jkasky,项目名称:clessc,代码行数:25,代码来源:UnprocessedStatement.cpp
示例13: processValue
const TokenList *ValueProcessor::processDeepVariable(
TokenList::const_iterator &i,
TokenList::const_iterator &end,
const ValueScope &scope) const {
const TokenList *var;
TokenList variable;
std::string key = "@";
if (i == end || (*i).type != Token::OTHER || (*i) != "@")
return NULL;
i++;
if (i == end || (*i).type != Token::ATKEYWORD ||
(var = scope.getVariable((*i))) == NULL) {
i--;
return NULL;
}
variable = *var;
processValue(variable, scope);
if (variable.size() != 1 || variable.front().type != Token::STRING) {
i--;
return NULL;
}
i++;
// generate key with '@' + var without quotes
variable.front().removeQuotes();
key.append(variable.front());
return scope.getVariable(key);
}
开发者ID:BramvdKroef,项目名称:clessc,代码行数:34,代码来源:ValueProcessor.cpp
示例14: _makeErrorMsg
Variable_array * VariableScript::parse(const c8 *text, size_t length, const Token::File *file) {
TokenList tokens;
if (m_lexer.scan(text, length, file, tokens) < 0) {
_makeErrorMsg("lexical error at %s", m_lexer.error().c_str());
return 0;
}
tokens.push_back(vnnew Token(file));
for (TokenList::iterator it = tokens.begin(); it != tokens.end(); ++it) {
LR_Parser::Result ret = m_parser.input(it->ptr());
if (ret == LR_Parser::kAccept) {
break;
}
if (ret == LR_Parser::kFailed) {
_makeErrorMsg("syntax error at %s(%u): %s", (file ? file->name.c_str() : ""), it->ptr()->row + 1, it->ptr()->text.c_str());
break;
}
}
LR_Node *root = m_parser.result();
if (root) {
root->grab();
m_parser.reset();
} else {
m_parser.reset();
return 0;
}
m_errorMsg.clear();
Variable_array *ret = vnnew Variable_array();
_build_value_list(root->child(0), ret);
root->drop();
return ret;
}
开发者ID:signorinotang,项目名称:tools,代码行数:32,代码来源:vnVariableScript.cpp
示例15: validateCondition
bool ValueProcessor::validateCondition(const TokenList &value,
const ValueScope &scope,
bool defaultVal) const {
TokenList::const_iterator i = value.begin();
TokenList::const_iterator end = value.end();
bool negate = false;
bool ret;
skipWhitespace(i, end);
if (*i == "not") {
negate = true;
i++;
}
ret = validateValue(i, end, scope, defaultVal);
skipWhitespace(i, end);
while (ret == true && i != value.end() && *i == "and") {
i++;
skipWhitespace(i, end);
ret = validateValue(i, end, scope, defaultVal);
skipWhitespace(i, end);
}
return negate ? !ret : ret;
}
开发者ID:BramvdKroef,项目名称:clessc,代码行数:31,代码来源:ValueProcessor.cpp
示例16: removeComments
int removeComments(TokenList &tokenList)
{
/*Fill in implementation */
Token *temp, *temp1;
int counter=0;
if(tokenList.getFirst() != nullptr)
{
temp = tokenList.getFirst();
while(temp)
{
temp1 = temp->getNext();
if(temp->getStringRep() == "--")//if the comment symbol is found
{
counter++;//counts how many comments are removed
tokenList.deleteToken(temp);//delets the comment symbol
temp = temp1;
temp1 = temp->getNext();
tokenList.deleteToken(temp);//deletes the comment body
temp= temp1;
}
else
{
temp = temp->getNext();
}
}
}
return counter;// returns the number of comments removed
}
开发者ID:jkosingh,项目名称:C-plus-plus-VHDL-parser---detailed-,代码行数:30,代码来源:implementation+file+parserClasses.cpp
示例17: getValue
// getValue
// Gets the value of the number/expression at the current position
// If the current value is an integer, return it
// If it's a parenthetical expression, evaluate, and return
// evalMultiplication is a flag used to ensure multiplication happens before addition
// If true, it will handle any multiplication that is applied to the current value
// That way, what is returned to the addition function is what we actually want to add
// Parameters:
// iter - the iterator for the list of tokens
// postExpr - the postfix expression we are converting to
// evalMultiplication (input boolean) whether to evaluate multiplication, see above
// Pre-condition: expr[pos] is an int or parenthesis
// Post-condition: expr[pos] is the end of the value
// If it was an int, it's on the int
// If it was a parenthesis, it's on the end parenthesis
// If handling multiplication, it's on the last multiplied int
// postExpr has the values handled here pushed to it
void getValue(ListIterator& iter, TokenList& postExpr, bool evalMultiplication)
{
bool negative = false;
if (!iter.currentIsInteger() && iter.tokenChar() == '-')
{
negative = true;
iter.advance();
}
if (iter.currentIsInteger())
{
postExpr.push_back(iter.integerValue());
if (negative)
{
postExpr.push_back(Token('~'));
}
while (evalMultiplication && isNextOperatorMultiplication(iter))
{
iter.advance();
handleMultiplyLevelOperation(iter, postExpr);
}
}
else
{
handleParenthesis(iter, postExpr);
if (negative)
{
postExpr.push_back(Token('~'));
}
}
}
开发者ID:evan1026,项目名称:CMPSC122---Homeworks,代码行数:52,代码来源:evaluate.cpp
示例18: getAssignmentStatements
Token* getAssignmentStatements(TokenList &tokenList)
{
Token* ptr = tokenList.getFirst(); //create a pointer pointing to the head of the full list of tokens from our cpp file
while(ptr) //until the pointer is at the end
{
//if statement for checking any assignment / compound assignment operators
if (ptr -> getStringRep() == "=" || ptr -> getStringRep() == "+=" ||
ptr -> getStringRep() == "-=" || ptr -> getStringRep() == "*=" ||
ptr -> getStringRep() == "/=" || ptr -> getStringRep() == "%=" ||
ptr -> getStringRep() == "^=" || ptr -> getStringRep() == "<<=" ||
ptr -> getStringRep() == ">>=" || ptr -> getStringRep() == "&=" || ptr -> getStringRep() == "|=")
{
numAssignmentStatements++;
//since form is (Variable = Expression), only one token before the assignment operator would be taken into account
ptr = ptr -> getPrev();
while (ptr -> getStringRep() != ";") //until a semicolon is found
{
//append the token string (part of the assignment statement) to the assigstats TokenList
assigstats.append(ptr->getStringRep());
ptr = ptr -> getNext(); //move pointer to next token
}
assigstats.append(ptr->getStringRep()); //append semicolon to assigstats
}
ptr = ptr -> getNext(); //move pointer to next token
}
return assigstats.getFirst(); //return the head pointer so we can begin traversing through the list
}
开发者ID:cemsezer95,项目名称:C-Parser,代码行数:27,代码来源:assignment3.cpp
示例19: while
// Here we have to find the character c, and expand the token T.
// only top-level characters are considered. Active chars are allowed.
// MX is decreased. Job aborted if it becomes negative.
bool token_ns::expand_nct(TokenList&L,Token T, int n, uchar c, int& MX)
{
TokenList res;
bool result = false;
TokenList Table[10]; // arguments of the commands
while(!L.empty()) {
Token t = L.front();
L.pop_front();
if(t.is_a_left_brace()) { // get a whole block
L.push_front(t); // re-enter the brace in the list
token_ns::fast_get_block(L,res);
continue;
}
if(t.cmd_val() == 10)
continue; // ignore spaces.
if(!(t.is_a_char() && t.char_val()==c)) { // just copy
res.push_back(t);
continue;
}
result = true; // We found something
MX--;
if(MX<0) return true;
for(int k=0;k<n;k++)
Table[k+1] = get_a_param(L,false);
TokenList W = the_parser.special_expand(Table);
L.splice(L.begin(),W);
}
L.splice(L.end(),res);
return result;
}
开发者ID:chenhaot,项目名称:oerpub.rhaptoslabs.tralics,代码行数:33,代码来源:txarray.C
示例20: removeInlineComments
//Removes all inline comments from the tokenList including the // marker
//Returns the number of comments removed
//tokenList must be existing object
int removeInlineComments(TokenList &tokenList) {
int count = 0; //counts the amount of inline comments removed
Token* temp;
//temp is going to be moved around the list looking for inline comments
temp = tokenList.getFirst();
//temp gets initialized to the first token in the list
while (temp) {
//this loop will run till you hit the end of the list (i.e NULL)
if (temp->getStringRep() == "//") {
count++;
//count as one inline comment to delete
Token* destroy1;
destroy1 = temp;
//make a token to use in destroying the //
if (temp->getNext() != NULL) {
//check to make sure you do not have a blank inline comment on the last line
//deletes the comment included in the inline comment
Token* destroy2;
destroy2 = temp->getNext();
temp = destroy2->getNext();
tokenList.deleteToken(destroy1);
tokenList.deleteToken(destroy2);
}
else {
delete temp;
}
}
else {
temp = temp->getNext();
}
}
return count;
}
开发者ID:TheChyz,项目名称:Parser,代码行数:37,代码来源:assignment2.cpp
注:本文中的TokenList类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论