public static void leUmTokenValido() { Erro.setErro(false); if (resultAS.Read()) { Token.setCodigo("" + resultAS.GetInt32(0)); Token.setToken(resultAS.GetString(1)); Token.setTipo(resultAS.GetString(2)); Token.setLinha("" + resultAS.GetInt32(3)); } else { Erro.setErro(true); } }
public static void consultaUmToken() { OleDbDataReader result; String aux = "select * from TTokens where Token ='" + Token.getToken() + "'"; strSQL = new OleDbCommand(aux, conn); result = strSQL.ExecuteReader(); Erro.setErro(false); if (result.Read()) { Token.setCodigo("" + result.GetInt32(0)); } else { Erro.setErro("Linha " + Token.getLinha() + ": " + Token.getToken() + " (Token não identificado)"); } }
public static void scanner() { FileStream infile; int tam; int kl = 1; char x; String aux = ""; infile = new System.IO.FileStream("pftmp.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read); MeuCompiladorDAL.deletaTTokensValidos(); tam = (int)infile.Length; for (int i = 0; i < tam; ++i) { x = (char)infile.ReadByte(); if (char.IsDigit(x)) { while (char.IsDigit(x)) { aux = aux + x; x = (char)infile.ReadByte(); ++i; } Token.setCodigo("200"); Token.setToken(aux); Token.setTipo("Inteiro"); Token.setLinha(kl.ToString()); MeuCompiladorDAL.inseriUmTokenValido(); aux = ""; } if (char.IsLetter(x)) { aux = ""; while (char.IsLetter(x)) { aux = aux + x; x = (char)infile.ReadByte(); ++i; } Token.setToken(aux); Token.setTipo("String"); Token.setLinha(kl.ToString()); MeuCompiladorDAL.consultaUmToken(); if (Erro.getErro()) { return; } else { MeuCompiladorDAL.inseriUmTokenValido(); } aux = ""; } if (char.IsPunctuation(x) || char.IsSymbol(x)) { Token.setToken(x.ToString()); Token.setTipo("Delimitador"); Token.setLinha(kl.ToString()); MeuCompiladorDAL.consultaUmToken(); if (Erro.getErro()) { return; } else { MeuCompiladorDAL.inseriUmTokenValido(); } } if (x == 13) { ++kl; } } infile.Close(); }