//pos = Posição que a leitura esta sendo feita //linhaerro, colunaerro = Linha e coluna que ocorreu o erro //erro = Se ocorreu erro ou não public static void Preencher_analisadorLexico() { controleDadosSimbolos sim1 = new controleDadosSimbolos("inicio", "inicio", " "); tabelaSimbolo.Add("inicio", sim1); //tabeladesimbolos.Add("inicio", sim1); controleDadosSimbolos sim2 = new controleDadosSimbolos("varinicio", "varinicio", " "); tabelaSimbolo.Add("varinicio", sim2); //tabelahash.tabeladesimbolos.Add("varinicio", sim2); controleDadosSimbolos sim3 = new controleDadosSimbolos("varfim", "varfim", " "); tabelaSimbolo.Add("varfim", sim3); //tabelahash.tabeladesimbolos.Add("varfim", sim3); controleDadosSimbolos sim4 = new controleDadosSimbolos("escreva", "escreva", " "); tabelaSimbolo.Add("escreva", sim4); //tabelahash.tabeladesimbolos.Add("escreva", sim4); controleDadosSimbolos sim5 = new controleDadosSimbolos("leia", "leia", " "); tabelaSimbolo.Add("leia", sim5); //tabelahash.tabeladesimbolos.Add("leia", sim5); controleDadosSimbolos sim6 = new controleDadosSimbolos("se", "se", " "); tabelaSimbolo.Add("se", sim6); //tabelahash.tabeladesimbolos.Add("se", sim6); controleDadosSimbolos sim7 = new controleDadosSimbolos("entao", "entao", " "); tabelaSimbolo.Add("entao", sim7); //tabelahash.tabeladesimbolos.Add("entao", sim7); controleDadosSimbolos sim8 = new controleDadosSimbolos("fimse", "fimse", " "); tabelaSimbolo.Add("fimse", sim8); //tabelahash.tabeladesimbolos.Add("fimse", sim8); controleDadosSimbolos sim9 = new controleDadosSimbolos("fim", "fim", " "); tabelaSimbolo.Add("fim", sim9); //tabelahash.tabeladesimbolos.Add("fim", sim9); controleDadosSimbolos sim10 = new controleDadosSimbolos("inteiro", "inteiro", " "); tabelaSimbolo.Add("inteiro", sim10); //tabelahash.tabeladesimbolos.Add("inteiro", sim10); controleDadosSimbolos sim11 = new controleDadosSimbolos("literal", "literal", " "); tabelaSimbolo.Add("literal", sim11); //tabelahash.tabeladesimbolos.Add("literal", sim11); controleDadosSimbolos sim12 = new controleDadosSimbolos("real", "real", " "); tabelaSimbolo.Add("real", sim12); //tabelahash.tabeladesimbolos.Add("real", sim12); }
public static void getSintatico() { Pilha_SEM = new Stack <controleDadosSimbolos>(); Stack <int> estado = new Stack <int>(); int state; analisadorLexico.Preencher_analisadorLexico(); controleDadosSimbolos simbolo = analisadorLexico.getLex(0); estado.Push(0); string erroencontrado; while (true) { //estado no topo da pilha state = estado.Peek(); //identificando erro if (state == 132) { estado.Pop(); state = estado.Peek(); erroencontrado = getErro(state); Console.WriteLine("\nErro encontrado no estado: " + state + " - " + erroencontrado); Console.Write("\n" + simbolo.Lexema); analisadorLexico.getLinhaColuna(); return; } //se vai empilhar if ((getACTION(state, simbolo.Token) > 0) && (getACTION(state, simbolo.Token) != 151)) { estado.Push(getACTION(state, simbolo.Token)); Pilha_SEM.Push(simbolo); simbolo = analisadorLexico.getLex(analisadorLexico.pos);//proximo lexema //se vai haver redução } else if (getACTION(state, simbolo.Token) <= 0) { int reduce = getACTION(state, simbolo.Token) * (-1); //voltar ao numero verdadeiro da producao a ser reduzida String sentenca = getSentenca(reduce); //procurando a sentenca que esta sendo reduzida //encontrar a quantidade de simbolos de beta int qtdSimbolosBeta = 0; Boolean isBeta = false; //guardar o não terminal StringBuilder nonTerminal = new StringBuilder(); string ALFA = ""; string BETA = ""; //recuperando a quantidade de simbolos beta for (int i = 0; i < sentenca.Length; i++) { //antes de -> if (isBeta == false && sentenca[i] != '-') { ALFA += sentenca[i]; } // apos -> if (sentenca[i] == '-' && sentenca[i + 1] == '>') { isBeta = true; i = i + 2; } if (isBeta == true) { BETA += sentenca[i]; } if (sentenca[i] == ' ' && isBeta == true) { qtdSimbolosBeta++; } } int j = 0; //Recuperando o não terminal while (sentenca[j] != ' ') { nonTerminal.Append(sentenca[j]); j++; } //Desempilha qtdSimbolosBeta de estados for (int i = 0; i < qtdSimbolosBeta; i++) { estado.Pop(); } state = estado.Peek();//estado t é o topo da pilha estado.Push(getGOTO(state, nonTerminal.ToString())); Console.WriteLine("\n---------------------------------------------------------------------\n"); Console.WriteLine("\nSentenca reduzida: " + sentenca);//imprime a produção A->B string[] K = ALFA.Split(' '); callSemantica(reduce, K[0], qtdSimbolosBeta);//Chamando o analisador semantico //Se ha aceitacao } else if (getACTION(state, simbolo.Token) == 151) { Console.WriteLine("\nAceitacao!!!"); escreverPontoC(Tx_18, Tx_25); return; } } }
public static void callSemantica(int reduc, string ALFA, int qtdBETA) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(regras_sem[reduc - 1]); Console.ResetColor(); Dictionary <string, controleDadosSimbolos> Hash_SEM = new Dictionary <string, controleDadosSimbolos>(); controleDadosSimbolos aux; if (reduc == 18 || reduc == 25) { aux = new controleDadosSimbolos(Pilha_SEM.Peek().Lexema, Pilha_SEM.Peek().Token, Pilha_SEM.Peek().Tipo); Pilha_SEM.Pop(); //Hash_SEM["OPRD2"] = aux; Hash_SEM.Add("OPRD2", aux); aux = new controleDadosSimbolos(Pilha_SEM.Peek().Lexema, Pilha_SEM.Peek().Token, Pilha_SEM.Peek().Tipo); Pilha_SEM.Pop(); //Hash_SEM[aux.Token] = aux; Hash_SEM.Add(aux.Token, aux); aux = new controleDadosSimbolos(Pilha_SEM.Peek().Lexema, Pilha_SEM.Peek().Token, Pilha_SEM.Peek().Tipo); Pilha_SEM.Pop(); //Hash_SEM["OPR1"] = aux; Hash_SEM.Add("OPRD1", aux); } else { for (int i = 0; i < qtdBETA; i++) { aux = new controleDadosSimbolos(Pilha_SEM.Peek().Lexema, Pilha_SEM.Peek().Token, Pilha_SEM.Peek().Tipo); Hash_SEM.Add(aux.Token, aux); Pilha_SEM.Pop(); } } controleDadosSimbolos S = new controleDadosSimbolos("", ALFA, ""); if (reduc == 5) { escreverTXT("\n\n\n"); } else if (reduc == 6) { controleDadosSimbolos ID; ID = Hash_SEM["id"]; controleDadosSimbolos TIPO; TIPO = Hash_SEM["TIPO"]; if (TIPO.Tipo == "lit") { escreverTXT("literal " + ID.Lexema + ";"); } else if (TIPO.Tipo == "real") { escreverTXT("double " + ID.Lexema + ";"); } else { escreverTXT(TIPO.Tipo + " " + ID.Lexema + ";"); } analisadorLexico.att_tipo(ID.Lexema, TIPO.Tipo); } else if (reduc == 7) { S.Tipo = "int"; } else if (reduc == 8) { S.Tipo = "real"; } else if (reduc == 9) { S.Tipo = "lit"; } else if (reduc == 11) { controleDadosSimbolos ID = Hash_SEM["id"]; if (analisadorLexico.existe(ID.Lexema)) { if (ID.Tipo == "lit") { escreverTXT("scanf(\"%s\",&" + ID.Lexema + ");"); } else if (ID.Tipo == "int") { escreverTXT("scanf(\"%d\",&" + ID.Lexema + ");"); } else if (ID.Tipo == "real") { escreverTXT("scanf(\"%f\",&" + ID.Lexema + ");"); } } else { Console.WriteLine("Erro: Variável não declarada"); ERRO++; } } else if (reduc == 12) { controleDadosSimbolos ARG = Hash_SEM["ARG"]; if (ARG.Tipo == "lit") { escreverTXT("printf(\"%s\"," + ARG.Lexema + ");"); } else if (ARG.Tipo == "real") { escreverTXT("printf(\"%lf\"," + ARG.Lexema + ");"); } else if (ARG.Tipo == "int") { escreverTXT("printf(\"%d\"," + ARG.Lexema + ");"); } else { escreverTXT("printf(" + ARG.Lexema + ");"); } } else if (reduc == 13) { controleDadosSimbolos literal = Hash_SEM["literal"]; S.Lexema = literal.Lexema; S.Tipo = "literal"; } else if (reduc == 14) { controleDadosSimbolos num = Hash_SEM["num"]; S.Lexema = num.Lexema; S.Tipo = "num"; } else if (reduc == 15) { controleDadosSimbolos ID = Hash_SEM["id"]; if (analisadorLexico.existe(ID.Lexema)) { S.Lexema = ID.Lexema; S.Tipo = ID.Tipo; } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\n-->Erro: Variável não declarada.\n"); analisadorLexico.getLinhaColuna(); Console.ResetColor(); ERRO++; } } else if (reduc == 17) { controleDadosSimbolos ID = Hash_SEM["id"]; if (analisadorLexico.existe(ID.Lexema)) { controleDadosSimbolos LD = Hash_SEM["LD"]; if ((ID.Tipo == LD.Tipo) || (ID.Tipo == "real" && (LD.Tipo == "num" || LD.Tipo == "int"))) { controleDadosSimbolos rcb = Hash_SEM["rcb"]; rcb.Tipo = "="; escreverTXT(ID.Lexema + " " + rcb.Tipo + " " + LD.Lexema + ";"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\n-->Erro: Tipos diferentes para atribuição.\n"); analisadorLexico.getLinhaColuna(); Console.ResetColor(); ERRO++; } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\n-->Erro: Variável não declarada.\n"); analisadorLexico.getLinhaColuna(); Console.ResetColor(); ERRO++; } } else if (reduc == 18) { string tx = "T" + Tx_18; controleDadosSimbolos OPRD1 = Hash_SEM["OPRD1"]; controleDadosSimbolos OPRD2 = Hash_SEM["OPRD2"]; string[] tipos_equivalentes = { "num", "real", "int" }; if (OPRD1.Tipo != "lit" && OPRD2.Tipo != "lit") { S.Lexema = tx; S.Tipo = "int"; Tx_18 += 1; controleDadosSimbolos opm = Hash_SEM["opm"]; escreverTXT(tx + " = " + OPRD1.Lexema + " " + opm.Lexema + " " + OPRD2.Lexema + ";"); } else { S.Lexema = tx; S.Tipo = "num"; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("-->Erro: Operandos com tipos incompatíveis."); analisadorLexico.getLinhaColuna(); Console.ResetColor(); ERRO++; } } else if (reduc == 19) { controleDadosSimbolos OPRD = Hash_SEM["OPRD"]; S.Lexema = OPRD.Lexema; S.Tipo = OPRD.Tipo; } else if (reduc == 20) { controleDadosSimbolos ID = Hash_SEM["id"]; if (analisadorLexico.existe(ID.Lexema)) { S.Lexema = ID.Lexema; S.Tipo = ID.Tipo; } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("-->Erro: Variável não declarada."); analisadorLexico.getLinhaColuna(); Console.ResetColor(); ERRO++; } } else if (reduc == 21) { controleDadosSimbolos num = Hash_SEM["num"]; S.Lexema = num.Lexema; S.Tipo = num.Token; } else if (reduc == 23) { escreverTXT("}"); } else if (reduc == 24) { controleDadosSimbolos EXP_R = Hash_SEM["EXP_R"]; escreverTXT("if(" + EXP_R.Lexema + "){"); } else if (reduc == 25) { controleDadosSimbolos OPRD1 = Hash_SEM["OPRD1"]; controleDadosSimbolos OPRD2 = Hash_SEM["OPRD2"]; if ((OPRD1.Tipo == "lit" && OPRD2.Tipo == "lit") || (OPRD1.Tipo != "lit" && OPRD2.Tipo != "lit")) { string tx = "T" + Tx_25; S.Lexema = tx; S.Tipo = "boolean"; Tx_25++; controleDadosSimbolos opr = Hash_SEM["opr"]; if (opr.Lexema == "==") { escreverTXT(tx + " = " + OPRD1.Lexema + " == " + OPRD2.Lexema + ";"); } else if (opr.Lexema == "<>") { escreverTXT(tx + " = " + OPRD1.Lexema + " != " + OPRD2.Lexema + ";"); } else { escreverTXT(tx + " = " + OPRD1.Lexema + " " + opr.Lexema + " " + OPRD2.Lexema + ";"); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("-->Erro: Operandos com tipos incompatíveis."); analisadorLexico.getLinhaColuna(); Console.ResetColor(); ERRO++; } } Pilha_SEM.Push(S); }
public static controleDadosSimbolos getLex(int Posi) //Função que lê um arquivo, acha lexemas, insere na tabela e retorna o lexema { pos = Posi; //Atualização da posição da leitura long tam; //Tamanho da Stream int[] S = { 128, 1, 0, 69, 43, 45, 42, 47, 62, 60, 61, 40, 41, 59, 34, 129, 123, 125, 130, 10, 32, 32, 46, 95, 131, 19, 25, 132, 11, 12, 13, 14, 4, 1, 26, 9, 10, 8, 15, 132, 17, 132, 3, 131, 131, 131, 132, 132, 1, 0, 0, 0, 0, 6, 0, 0, 7, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 132, 15, 15, 132, 15, 15, 15, 15, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 132, 17, 18, 132, 17, 17, 17, 17, 17, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 19, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 21, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 21, 21, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 24, 132, 132, 23, 23, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 23, 24, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132 }; Stack <int> estados = new Stack <int>(); //Pilha dos estados da tabela tabelaTransicao[,] tabelaT = new tabelaTransicao[29, 24]; //Tabela de transição int t = 0; // for (int i = 0; i < 29; i++) // { // for (int j = 0; j < 24; j++) // { //Adicionando o vetor S a tabela de transição tabelaT[i, j] = new tabelaTransicao(S[t]); // t++; // } // } // tabelaErros tabelahashe = new tabelaErros(); //Tabela de erros simples tabelahashe.tabeladeerros.Add(1, "Identificador não permitido"); // tabelahashe.tabeladeerros.Add(16, "Constantes literais nao permitidas"); // tabelahashe.tabeladeerros.Add(18, "Erro de foramatacao de comentario (chaves)"); // tabelahashe.tabeladeerros.Add(21, "Constantes numericas nao permitidas"); // tabelahashe.tabeladeerros.Add(23, "Constantes numericas nao permitidas"); // tabelahashe.tabeladeerros.Add(24, "Constantes numericas nao permitidas"); // //Tente try { StringBuilder bffCaracter = new StringBuilder(); //Criando o buffer de caracteres StreamReader stream = File.OpenText("C:\\Users\\lucas\\Desktop\\Compilador\\FONTE.ALG"); //Abrindo o arquivo (Mudar caso necessário) int caracter = 0, linha = 1, coluna = 0; //Caracter = caracter atual stream.BaseStream.Position = pos; //Setando a leitura do arquivo para a posição necessária tam = stream.BaseStream.Length; //Tamanho total do arquivo estados.Push(tabelaT[linha, coluna].Elemento); //Colocando na tabela de estados o estado inicial 131 while (pos <= tam || erro == 0) //Enquanto a posição for menor que o tamanho total do arquivo ou encontrar algum erro { caracter = stream.Read(); //Lendo o caracter atual int test = 0; //Teste se o caracter esta na tabela ou não for (int i = 0; i < 24; i++) // { // if (tabelaT[0, i].Elemento == caracter) // { // coluna = i; //Testando se está ou não na tabela de transição test = 1; // } // } // //Caso o caracter não esteja na tabela if (test == 0 && caracter != 10 && caracter != 13 && caracter == 32) //Coloque ele na coluna que representa a coluna dos outros caracteres { coluna = 17; } if (test == 0 && (caracter == 10 || caracter == 13 || caracter == 32))//Verifico se o caracter é espaço, tab ou quebra linha { coluna = 19; } if (caracter == -1)//Verifico se o caracter é de fim de arquivo { coluna = 18; } if (char.IsDigit((char)caracter))//Verifico se o caracter é digido { coluna = 1; } //Tratando o problema do espaço no literal if (coluna == 21 && caracter == 32 && estados.Peek() == 15)//Se for espaço e o estado atual é literal não ignore { bffCaracter.Append((char)caracter); } //tratando o problema do \n if (caracter == 92 && estados.Peek() == 15)//Se for \n e o estado atual é de literal não ignore { coluna = 2; } if (char.IsLetter((char)caracter))//verificando se o caracter é letra { coluna = 2; } if ((caracter == 69 || caracter == 101) && (estados.Peek() == 19 || estados.Peek() == 21))//Tratando e|E { coluna = 3; } //Procura o estado atual que se encontra for (int i = 0; i < 29; i++) { if (tabelaT[i, 0].Elemento == estados.Peek()) { linha = i; } } estados.Push(tabelaT[linha, coluna].Elemento);//Adicionana na tabela de estados //Verificando se o estado atual é vazio ou de erro if (tabelaT[linha, coluna].Elemento == 0)//Caso seja o fim de um lexema { if (tabelaSimbolo.ContainsKey(bffCaracter.ToString())) //if (tabelahash.tabeladesimbolos.ContainsKey(bffCaracter.ToString()) == true)//Verifica se este lexema já esta na tabela { controleDadosSimbolos aux; //aux = (controleDadosSimbolos)tabelahash.tabeladesimbolos[bffCaracter.ToString()]; aux = tabelaSimbolo[bffCaracter.ToString()]; return(aux);//Se já estiver na tabela retorne ele } else//Caso não esteja na tabela - Buscar qual token este estado pertence { controleDadosSimbolos simaux; estados.Pop(); switch (estados.Peek()) { case 1: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opr", " "); return(simaux); case 2: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opr", " "); return(simaux); case 3: simaux = new controleDadosSimbolos("EOF", "EOF", " "); return(simaux); case 4: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opr", " "); return(simaux); case 5: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opr", " "); return(simaux); case 6: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "rcb", " "); return(simaux); case 7: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opr", " "); return(simaux); case 8: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "pt_v", " "); return(simaux); case 9: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "ab_p", " "); return(simaux); case 10: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "fc_p", " "); return(simaux); case 11: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opm", " "); return(simaux); case 12: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opm", " "); return(simaux); case 13: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opm", " "); return(simaux); case 14: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opm", " "); return(simaux); case 26: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "opm", " "); return(simaux); case 16: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "literal", "literal"); return(simaux); case 18: Console.WriteLine("Comentario " + bffCaracter); break; case 19: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "num", "inteiro"); return(simaux); case 21: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "num", "real"); return(simaux); case 24: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "num", "real"); return(simaux); case 25: simaux = new controleDadosSimbolos(bffCaracter.ToString(), "id", " "); tabelaSimbolo.Add(simaux.Lexema, simaux); return(simaux); default: Console.WriteLine("Erro na leitura da pilha ou formato do comentário errado!"); Console.WriteLine("\nLinha" + linhaerro + " Coluna " + colunaerro); erro = 1; break; } } estados.Clear(); //Limpar a tabela de estados após estados.Push(tabelaT[1, coluna].Elemento); //Adiciona o estado inicial bffCaracter.Remove(0, bffCaracter.Length); //E limpa o buffer } if (tabelaT[linha, coluna].Elemento == 132) //Caso o estado atual seja de erro { Console.WriteLine("ERRO ENCONTRADO - " + tabelahashe.tabeladeerros[linha]); // Console.WriteLine("\nlinha na tabela: " + linha + " Coluna: " + coluna); // Console.WriteLine("\nLinha: " + linhaerro + " Coluna: " + colunaerro); //Retornando o erro erro = 1; // controleDadosSimbolos simerro = new controleDadosSimbolos("ERRO", "ERRO", " "); // return(simerro); // } //Caso o caracter atual não seja espaço, tab ou quebra linha guarde ele no buffer if (caracter != 10 && caracter != 13 && caracter != 32) { bffCaracter.Append((char)caracter); } pos++; //Avança a posição if (caracter == 13) { linhaerro++; colunaerro = 0; } else { colunaerro++; } } stream.Close(); } catch (Exception e) //Caso não consiga abrir o arquivo { Console.Error.WriteLine("Erro na abertura do arquivo:" + e + "\n"); //retorne o erro } return(null); }