LookAhead() приватный Метод

private LookAhead ( int index ) : string
index int
Результат string
        //This function implements the DFA for th parser's lexer.
        //It generates a token which is used by the LALR state
        //machine.
        private Token LookAheadDFA(LookAheadBuffer lookAheadBuffer)
        {
            string ch = lookAheadBuffer.LookAhead(1);

            if (String.IsNullOrEmpty(ch) || ch[0] == Char.MaxValue)
            {
                return new Token(egtDataManager.GetFirstSymbolOfType(SymbolType.End), String.Empty)
                {
                    StartPosition = lookAheadBuffer.Position,
                    EndPosition = lookAheadBuffer.Position
                };
            }

            int currentDFA = 0;
            int lookAheadPosition = 1;
            //Next byte in the input Stream
            int lastAcceptState = -1;
            //We have not yet accepted a character string
            int lastAcceptPosition = -1;

            while (true)
            {
                bool found = false;
                ch = lookAheadBuffer.LookAhead(lookAheadPosition);

                if (!String.IsNullOrEmpty(ch))
                {
                    foreach (FAEdge edge in egtDataManager.GetFAState(currentDFA).Edges)
                    {
                        //Look for character in the Character Set Table
                        if (edge.Characters.Contains(ch[0]))
                        {
                            int target = edge.Target;

                            if (egtDataManager.GetFAState(target).Accept != null)
                            {
                                lastAcceptState = target;
                                lastAcceptPosition = lookAheadPosition;
                            }

                            currentDFA = target;
                            lookAheadPosition++;

                            found = true;
                            break;
                        }
                    }
                }

                if (!found)
                {
                    Symbol symbol = null;
                    string data = String.Empty;

                    // Lexer cannot recognize symbol
                    if (lastAcceptState == -1)
                    {
                        symbol = egtDataManager.GetFirstSymbolOfType(SymbolType.Error);
                        data = lookAheadBuffer.GetTextFromBuffer(1);
                    }
                    else
                    {
                        symbol = egtDataManager.GetFAState(lastAcceptState).Accept;
                        data = lookAheadBuffer.GetTextFromBuffer(lastAcceptPosition);
                    }

                    return new Token(symbol, data)
                    {
                        StartPosition = lookAheadBuffer.Position
                    };
                }
            }
        }
Пример #2
0
        //This function implements the DFA for th parser's lexer.
        //It generates a token which is used by the LALR state
        //machine.
        private Token LookAheadDFA(LookAheadBuffer lookAheadBuffer)
        {
            string ch = lookAheadBuffer.LookAhead(1);

            if (String.IsNullOrEmpty(ch) || ch[0] == Char.MaxValue)
            {
                return(new Token(egtDataManager.GetFirstSymbolOfType(SymbolType.End), String.Empty)
                {
                    StartPosition = lookAheadBuffer.Position,
                    EndPosition = lookAheadBuffer.Position
                });
            }

            int currentDFA        = 0;
            int lookAheadPosition = 1;
            //Next byte in the input Stream
            int lastAcceptState = -1;
            //We have not yet accepted a character string
            int lastAcceptPosition = -1;

            while (true)
            {
                bool found = false;
                ch = lookAheadBuffer.LookAhead(lookAheadPosition);

                if (!String.IsNullOrEmpty(ch))
                {
                    foreach (FAEdge edge in egtDataManager.GetFAState(currentDFA).Edges)
                    {
                        //Look for character in the Character Set Table
                        if (edge.Characters.Contains(ch[0]))
                        {
                            int target = edge.Target;

                            if (egtDataManager.GetFAState(target).Accept != null)
                            {
                                lastAcceptState    = target;
                                lastAcceptPosition = lookAheadPosition;
                            }

                            currentDFA = target;
                            lookAheadPosition++;

                            found = true;
                            break;
                        }
                    }
                }

                if (!found)
                {
                    Symbol symbol = null;
                    string data   = String.Empty;

                    // Lexer cannot recognize symbol
                    if (lastAcceptState == -1)
                    {
                        symbol = egtDataManager.GetFirstSymbolOfType(SymbolType.Error);
                        data   = lookAheadBuffer.GetTextFromBuffer(1);
                    }
                    else
                    {
                        symbol = egtDataManager.GetFAState(lastAcceptState).Accept;
                        data   = lookAheadBuffer.GetTextFromBuffer(lastAcceptPosition);
                    }

                    return(new Token(symbol, data)
                    {
                        StartPosition = lookAheadBuffer.Position
                    });
                }
            }
        }