Beispiel #1
0
    static bool scan(ref CStyxScanner scanner)
    {
        string token = "", tid = "";
        short  gcnt = scanner.getGroups();
        int    tlen = 0;

        if (gcnt <= 0)
        {
            for (short tcnt = scanner.getTokens(), i = 0; i < tcnt; ++i)
            {
                token = scanner.getTokenID(i, -1);
                tid   = scanner.externalTokenID(ref token);
                tlen  = Math.Max(tlen, tid.Length);
            }
        }
        else
        {
            for (short i = 0; i < gcnt; ++i)
            {
                for (short tcnt = scanner.getTokens(i), j = 0; j < tcnt; ++j)
                {
                    token = scanner.getTokenID(j, i);
                    tid   = scanner.externalTokenID(ref token);
                    tlen  = Math.Max(tlen, tid.Length);
                }
            }
        }
        bool ok = true;

        while ((ok = scanner.nextToken()))
        {
            string Value = "";
            if (scanner.currentToken(ref token, ref Value))
            {
                tid = scanner.externalTokenID(ref token);

/*
 *      Console.WriteLine
 *      (
 *        "LINE=" + scanner.getLine() + ", COL=" + scanner.getCol() +
 *        ", TOK=" + tid + ", VAL=" + Value + "\n"
 *      );
 */
                Console.WriteLine
                (
                    "LINE={0,6:d}, COL={1,5:d}, TOK={2}, VAL={3}",
                    scanner.getLine(), scanner.getCol(), tid.PadRight(tlen), Value
                );
            }
            else
            {
                Console.Error.WriteLine("currentToken failed\n");
                break;
            }
            if (scanner.eos())
            {
                break;
            }
        }
        if (!ok)
        {
            Console.Error.WriteLine("nextToken failed\n");
        }
        return(ok);
    }