private ASCIITableState GetState(int index)
 {
     while (m_tabela.Count <= index)
     {
         m_tabela.Add(null);
     }
     if (m_tabela[index] == null)
     {
         m_tabela[index] = new ASCIITableState();
     }
     return(m_tabela[index]);
 }
        public bool ProcessInput()
        {
            while (true)
            {
                int input = GetInput();

                if ((CurrentState < 0 || CurrentState >= m_tabela.Count) || (m_tabela[CurrentState] == null))
                {
                    if (input == INPUT_EOF)
                    {
                        Debug.WriteLine(String.Format("Parada por EOF"));
                    }
                    else
                    {
                        Debug.WriteLine(String.Format("Parada por estado inválido: {0}", CurrentState));
                    }
                    break;
                }

                ASCIITableState estadoAtual = m_tabela[CurrentState];
                int             target      = estadoAtual.GetTarget(input);
                if (target <= 0)
                {
                    Debug.WriteLine(String.Format("Parada por estado inválido: {0}", target));
                    break;
                }

                NextState = target & TARGET_STATE_MASK;

                char dc = '?';
                if (input >= 32 && input < 127)
                {
                    dc = (char)input;
                }

                Debug.WriteLine("{0} -> '{1}'({2}) -> {3}", CurrentState, dc, input, NextState);

                if (NextState == SUCCESS_STATE)
                {
                    Debug.WriteLine("Parada por SUCCESS_STATE");
                    return(true);
                }
                else if (NextState == FAILED_STATE)
                {
                    Debug.WriteLine("Parada por FAILED_STATE");
                    break;
                }

                // ----------------------------

                if ((target & (int)eScannerStateModifiers.e01ReturnToken) != 0)
                {
                    ReturnToken(estadoAtual.GetId(input));
                }

                if ((target & (int)eScannerStateModifiers.e02ClearToken) != 0)
                {
                    ClearToken();
                }

                if ((target & (int)eScannerStateModifiers.e03InsertToken) != 0)
                {
                    InsertToken(input);
                }

                // ----------------------------

                if ((target & (int)eScannerStateModifiers.e04ReturnToken) != 0)
                {
                    ReturnToken(estadoAtual.GetId(input));
                }

                if ((target & (int)eScannerStateModifiers.e05ClearToken) != 0)
                {
                    ClearToken();
                }

                if ((target & (int)eScannerStateModifiers.e06InsertToken) != 0)
                {
                    InsertToken(input);
                }

                // ----------------------------

                if ((target & (int)eScannerStateModifiers.e07ReturnToken) != 0)
                {
                    ReturnToken(estadoAtual.GetId(input));
                }

                if ((target & (int)eScannerStateModifiers.e08ClearToken) != 0)
                {
                    ClearToken();
                }

                if ((target & (int)eScannerStateModifiers.e09InsertToken) != 0)
                {
                    InsertToken(input);
                }

                // ----------------------------

                if ((target & (int)eScannerStateModifiers.e10PushBack) != 0)
                {
                    SetInput(input);
                }

                // ----------------------------

                LastState    = CurrentState;
                CurrentState = NextState;
            }
            return(false);
        }
        public void SetStateSuccessEOF(int stateIndex)
        {
            ASCIITableState state = GetState(stateIndex);

            state.SetState(SUCCESS_STATE, INPUT_EOF, eScannerStateModifiers.eNenhum, NO_ID);
        }
        public void SetStateFail(int stateIndex)
        {
            ASCIITableState state = GetState(stateIndex);

            state.SetState(FAILED_STATE, eScannerStateModifiers.eNenhum, NO_ID);
        }
        public void SetState(int fromState, int toState, string chars, eScannerStateModifiers modifiers, int returnId)
        {
            ASCIITableState state = GetState(fromState);

            state.SetState(toState, chars, modifiers, returnId);
        }