Example #1
0
 protected TableStateInfo GetState(int state)
 {
     while (m_tabela.Count <= state)
     {
         m_tabela.Add(null);
     }
     if (m_tabela[state] == null)
     {
         m_tabela[state] = new TableStateInfo(state);
     }
     return(m_tabela[state]);
 }
Example #2
0
        public bool InternalProccessInput(bool returnOneToken)
        {
            int  input   = Scanner.INPUT_EOF;
            bool retorno = false;

            while (true)
            {
                if ((CurrentState < 0 || CurrentState >= m_tabela.Count) || (m_tabela[CurrentState] == null))
                {
                    string msg;
                    if (input == Scanner.INPUT_EOF)
                    {
                        msg = "Fim de arquivo encontrado.";
                    }
                    else
                    {
                        msg = "Estado inválido encontrado.";
                    }
                    FinalState = Scanner.INVALID_STATE;
                    OnError(msg);
                    break;
                }

                input = GetInput();

                TableStateInfo estadoAtual = m_tabela[CurrentState];
                int            target      = estadoAtual.GetTarget(input);
                if (target <= 0)
                {
                    string msg;
                    if (input == Scanner.INPUT_EOF)
                    {
                        msg = "Fim de arquivo inesperado encontrado.";
                    }
                    else
                    {
                        msg = String.Format("Caracter inválido encontrado: {0}", (char)input);
                    }
                    FinalState = Scanner.INVALID_STATE;
                    OnError(msg);
                    break;
                }

                NextState = target & TARGET_STATE_MASK;

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

                if (NextState == Scanner.SUCCESS_STATE)
                {
                    FinalState = Scanner.SUCCESS_STATE;
                    retorno    = true;
                    break;
                }
                else if (NextState == Scanner.FAILED_STATE)
                {
                    FinalState = Scanner.FAILED_STATE;
                    OnError("Falha no reconhecimento da entrada");
                    break;
                }

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

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

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

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

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

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

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

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

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

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

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

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

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

                if ((target & (int)eStateModifiers.e10PushBack) != 0)
                {
                    PushInput(input);
                }

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

                LastState    = CurrentState;
                CurrentState = NextState;

                if (returnOneToken && Tokens.Count > 0)
                {
                    break;
                }
            }
            return(retorno);
        }
Example #3
0
        private void SetState(int fromState, int toState, string chars, eStateModifiers modifiers, int tokenId)
        {
            TableStateInfo state = GetState(fromState);

            state.SetState(toState, chars, modifiers, tokenId);
        }
Example #4
0
        private void SetStateSuccessEOF(int stateIndex)
        {
            TableStateInfo state = GetState(stateIndex);

            state.SetState(Scanner.SUCCESS_STATE, Scanner.INPUT_EOF, eStateModifiers.eNenhum, Scanner.NO_TOKEN_ID);
        }
Example #5
0
        private void SetStateFailEOF(int stateIndex)
        {
            TableStateInfo state = GetState(stateIndex);

            state.SetState(Scanner.FAILED_STATE, Scanner.INPUT_EOF, eStateModifiers.eNenhum, Scanner.NO_TOKEN_ID);
        }