AIMA.Core.Logic.FOL.Parsing.FOLLexer.nextToken C# (CSharp) Method

nextToken() public method

public nextToken ( ) : Token
return AIMA.Core.Logic.Common.Token
        public override Token nextToken()
        {
            if (lookAhead(1) == '(')
            {
                consume();
                return new Token((int)LogicTokenTypes.LPAREN, "(");

            }
            else if (lookAhead(1) == ')')
            {
                consume();
                return new Token((int)LogicTokenTypes.RPAREN, ")");

            }
            else if (lookAhead(1) == ',')
            {
                consume();
                return new Token((int)LogicTokenTypes.COMMA, ",");

            }
            else if (identifierDetected())
            {
                // System.Console.WriteLine("identifier detected");
                return identifier();
            }
            else if (char.IsWhiteSpace(lookAhead(1)))
            {
                consume();
                return nextToken();
            }
            else if ((int)lookAhead(1) == 65535)
            {
                return new Token((int)LogicTokenTypes.EOI, "EOI");
            }
            else
            {
                throw new ApplicationException("Lexing error on character "
                        + lookAhead(1));
            }
        }

Usage Example

Example #1
0
        protected void loadNextTokenFromInput()
        {
            bool eoiEncountered = false;

            for (int i = 0; i < _lookAhead - 1; i++)
            {
                lookAheadBuffer[i] = lookAheadBuffer[i + 1];
                if (isEndOfInput(lookAheadBuffer[i]))
                {
                    eoiEncountered = true;
                    break;
                }
            }
            if (!eoiEncountered)
            {
                try
                {
                    lookAheadBuffer[_lookAhead - 1] = lexer.nextToken();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }