public void load() { string[] datos = tablas.Split(); Escaner data = new Escaner(datos); List <Token> items = new List <Token>(); items = data.output(); tablasSemanticas = new Semantic(items); tablasSemanticas.fill(); //tablasSemanticas.print(); }
private void button1_Click_1(object sender, EventArgs e) { load(); gridErr.Rows.Clear(); string[] datos = richTextBox1.Lines; Escaner scan = new Escaner(datos); tokens = scan.output(); tablasSemanticas.dml = tokens; /*foreach (Token i in tokens) * { * Console.WriteLine(i.Dato + " " + i.Codigo); * * }*/ Parser parser = new Parser(datos); parser.scan = scan; parser.tokens = tokens; parser.semantica = tablasSemanticas; //Console.WriteLine((parser.analyze())? "Todo salió bien :) TQM":"El Query está mal, como todo en tu vida"); if (parser.analyze()) { gridErr.Rows.Add("1", "100", "Sin error"); gridErr.Rows.Add("2", "200", "Sin error"); gridErr.Rows.Add("3", "300", "Sin error"); SqlConnection conectar = new SqlConnection(conection); SqlDataAdapter adapter; dt = new DataTable(); conectar.Open(); if (conectar.State == System.Data.ConnectionState.Open) { try { string query = richTextBox1.Text; adapter = new SqlDataAdapter(query, conectar); adapter.Fill(dt); queryGrid.DataSource = dt; formatQueryTable(); //SqlCommand cmd = new SqlCommand(query, conectar); //cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine("Error: " + ex); } } conectar.Close(); } else { if (parser.scan.errores().Count > 0) { foreach (Token error in parser.scan.errores()) { if (error.Tipo == -1) { gridErr.Rows.Add(1, 102, "Error en línea " + error.Linea + " Elemento inválido: " + error.Dato); } else { gridErr.Rows.Add(1, 101, "Error en línea " + error.Linea + " Símbolo desconocido: " + error.Dato); } } } else { gridErr.Rows.Add("1", "100", "Sin error"); foreach (Token error in parser.errores) { if (error.Codigo > 300) { gridErr.Rows.Add("2", "200", "Sin error"); gridErr.Rows.Add("3", error.Codigo, "Error en línea: " + error.Linea + " " + error.Dato); } else { gridErr.Rows.Add("2", error.Codigo, "Error en línea: " + error.Linea + " " + error.Dato); } } } } }