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


C++ Scanner::NextToken方法代码示例

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


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

示例1: TestScanner

void TestScanner()
{
  TestBegin("Scanner");

  Scanner s;
  Token tok;

  s.From(
    "    \t\n"
    "  \ta.b = 1;\n"
    "  > < == <= >=  != =~ && || . , : ; [ ] ( ) { } = + += -= *\r\n"
    "123 0123 0xafbDDdd00\r"
    "01233999 00. 1E9 1E-9 1e+9 1.1e900\n"
    "\'fasdfa/#@[email protected]@@\\n\'\n"
    "\"fjalksdfjal#@[email protected]#[email protected]#\\n\"\n"
    "_abcd\r"
  );

  while( s.NextToken(&tok) && tok.Rep() != TOK_eof ){
    tok.Print();
    std::putchar('\n');
  }

  TestEnd();
}
开发者ID:CretescuMihai,项目名称:lab,代码行数:25,代码来源:scanner.cpp

示例2: ReadSyntaxFile

void Syntax::ReadSyntaxFile(Scanner &scanner, uint indents)
// ----------------------------------------------------------------------------
//   Parse the syntax description table
// ----------------------------------------------------------------------------
{
    enum State
    {
        inUnknown, inPrefix, inInfix, inPostfix,
        inComment, inCommentDef,
        inText, inTextDef,
        inBlock, inBlockDef,
        inSyntaxName, inSyntax, inSyntaxDef
    };

    State       state = inUnknown;
    text        txt, entry;
    token_t     tok = tokNAME;
    int         priority = 0;
    bool        done = false;
    ChildSyntax *childSyntax = NULL;

    while(tok != tokEOF && !done)
    {
        tok = scanner.NextToken(true);

        if (tok == tokSYMBOL || state >= inComment)
        {
            text t = scanner.TextValue();
            uint i, len = t.length();
            for (i = 1; i < len; i++)
            {
                text sub = t.substr(0, i);
                known_prefixes.insert(sub);
            }
            known_tokens.insert(t);
        }

        switch(tok)
        {
        case tokEOF:
            break;
        case tokINTEGER:
            priority = scanner.IntegerValue();
            break;
        case tokINDENT:
        case tokPAROPEN:
            indents++;
            break;
        case tokUNINDENT:
        case tokPARCLOSE:
            indents--;
            if (!indents)
                done = true;
            break;
        case tokNAME:
        case tokSYMBOL:
        case tokSTRING:
        case tokQUOTE:
            txt = scanner.TextValue();

            if (txt == "NEWLINE")
                txt = "\n";
            else if (txt == "INDENT")
                txt = Block::indent;
            else if (txt == "UNINDENT")
                txt = Block::unindent;

            if (txt == "INFIX")
                state = inInfix;
            else if (txt == "PREFIX")
                state = inPrefix;
            else if (txt == "POSTFIX")
                state = inPostfix;
            else if (txt == "BLOCK")
                state = inBlock;
            else if (txt == "COMMENT")
                state = inComment;
            else if (txt == "TEXT")
                state = inText;
            else if (txt == "SYNTAX")
                state = inSyntaxName;

            else if (txt == "STATEMENT")
                statement_priority = priority;
            else if (txt == "FUNCTION")
                function_priority = priority;
            else if (txt == "DEFAULT")
                default_priority = priority;

            else switch(state)
            {
            case inUnknown:
                break;
            case inPrefix:
                prefix_priority[txt] = priority;
                break;
            case inPostfix:
                postfix_priority[txt] = priority;
                break;
            case inInfix:
//.........这里部分代码省略.........
开发者ID:c3d,项目名称:elfe,代码行数:101,代码来源:syntax.cpp


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