Example #1
0
        /*
         *-----------------------------------------------------Tratamentos em geral--------------------------------------------------------------
         *-------------------------------------------------------Fim--------------------------------------------------------------------------
         */


        private void classificaTokens(ref Token token, ref Erro erro)
        {
            if (reservadas.Contains(token.getLexema()) || isSeparador(token.getLexema())) //classifica reservadas e separadores
            {
                token.setToken(token.getLexema());
            }
            else
            {
                if (token.getLexema().Equals("var"))//declaração global
                {
                    nomeSubAtual = "global";
                }
                if (token.getLexema()[0] == '#')
                {
                    if (token.getLexema().Length > 1)
                    {
                        nomeSubAtual = token.getLexema();
                        token.setToken(token.getLexema() + "_DECL");
                        listaFuncoes.Add(nomeSubAtual);
                    }
                    else
                    {
                        erro.NLinha = token.getLinha();
                        erro.Tipo   = "léxico";
                        erro.Msg    = "Símbolo não reconhecido!";
                    }
                }
                else
                if (token.getLexema().Equals("@principale"))
                {
                    token.setToken("@principale");
                }
                else
                if (token.getLexema()[0] == '$')         //classifica literais
                {
                    token.setToken("literal");
                }
                else
                {
                    if (isNumero(token.getLexema()))         //classifica numeros inteiros
                    {
                        token.setToken("num_int");
                    }
                    else
                    if (token.getLexema().Contains('.'))             //possivel numero real
                    {
                        String possivelNumReal = token.getLexema().Replace('.', ',');
                        if (isNumReal(possivelNumReal))
                        {
                            token.setToken("num_real");
                        }
                        else
                        {
                            erro.NLinha = token.getLinha();
                            erro.Tipo   = "léxico";
                            erro.Msg    = "Símbolo não reconhecido!";
                        }
                    }
                    else
                    {
                        if (contemApenasLetras(token.getLexema()))             //contem apenas letras?
                        {
                            if (!listaFuncoes.Contains("#" + token.getLexema()))
                            {
                                token.setToken("id");
                                token.setAtributo(nomeSubAtual);
                            }
                            else             //chamada subRotina
                            {
                                token.setToken(token.getLexema() + "_CHAM");
                            }
                        }
                        else
                        {
                            if (isVetor(token.getLexema()))
                            {
                                token.setToken("vetor");
                            }
                            else
                            {
                                erro.NLinha = token.getLinha();
                                erro.Tipo   = "léxico";
                                erro.Msg    = "Símbolo não reconhecido!";
                            }
                        }
                    }
                }
            }
        }