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


C++ token::appendChar方法代码示例

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


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

示例1: followingChars

//function that finds if the chars following match a target symbol
bool followingChars(string target, char currentChar, token curToken)
{
    for(int x = 0; x < target.length(); x++)
    {
        if(currentChar == target[x])
        {
            curToken.appendChar(currentChar);
            currentChar = filestream.get();
        }
        else
        {
            curToken.clearData();
            while(x != 0)
            {
                filestream.unget();
                x--;
            }
            return false;
        }
    }
    filestream.unget();
    return true;
}
开发者ID:zakattak,项目名称:CalcInterpret,代码行数:24,代码来源:lexer.cpp

示例2: calcLex

//this function finds the next token and outputs it
token calcLex()
{
    curToken.clearData();
    char currentChar;

    while(1) //infinite loop, breaks through a return statement
    {
        //get the next char!
        currentChar = filestream.get();

        //used to ignore whitespace as a token
        while( currentChar == ' ' || currentChar == '\t' || currentChar == '\n')
        {
            currentChar = filestream.get();
        };

        //if the current char is the end of a file, it returns the end of file symbol
        if(currentChar == EOF)
        {
            curToken.type(endOfFileSym);
            return curToken;
        }

        //this is the comment logic: if the next chars are /*...
        if(followingChars("/*", currentChar, curToken))
        {
            //then while it isn't ending the line, or finding the end of comment sentinel...
            while(currentChar != '\n' && !followingChars("*/", currentChar, curToken))
            {
                //move onto the next character
                currentChar = filestream.get();
            }
            //move to the next character after the comment or line has ended
            //hop back up to the top of the while loop
            continue;
        }
        //if the chars ":=" are found, return the assignment symbol
        if(followingChars(":=", currentChar, curToken))
        {
            curToken.type(assignSym);
            curToken.data(":=");
            return curToken;
        }
        //if the chars "read" are found, return the read symbol
        if(followingChars("read", currentChar, curToken))
        {
            curToken.type(readSym);
            curToken.data("read");
            return curToken;
        }
        //if the chars "write" are found, return the write symbol
        if(followingChars("write", currentChar, curToken))
        {
            curToken.type(writeSym);
            curToken.data("write");
            return curToken;
        }

        //if this is put above the followingChars, it adds a duplicate letter.
        curToken.appendChar(currentChar);

        //checks for identifier strings only starting with letters and underscores
        if( isalpha(currentChar) || (currentChar == '_') )
        {
            while( isalnum(currentChar = filestream.get()) || (currentChar == '_'))
            {
                curToken.appendChar(currentChar);
            }
            //once the currentChar falls off the end of the identifier string, it must hop back to read the next one
            filestream.unget();
            //returns the identifier int
            curToken.type(identifier);
            return curToken;
        }

        //if the current char is a number
        if(isdigit(currentChar))
        {
            while ( isdigit(currentChar = filestream.get()) || currentChar == '.')
            {
                if (currentChar == '.')
                {
                    curToken.appendChar(currentChar);
                    currentChar = filestream.get();
                    if (!isdigit(currentChar))
                    {
                        curToken.type(numConstError);
                        return curToken;
                    }
                    while (isdigit(currentChar))
                    {
                        curToken.appendChar(currentChar);
                        currentChar = filestream.get();
                    }
                    filestream.unget();
                    curToken.type(numConst);
                    return curToken;
                }
                curToken.appendChar(currentChar);
//.........这里部分代码省略.........
开发者ID:zakattak,项目名称:CalcInterpret,代码行数:101,代码来源:lexer.cpp


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