private void button1_Click(object sender, EventArgs e) { string f = textBox1.Text; try { string output = f + "_output.txt"; writer = new StreamWriter(output); string file_text = File.ReadAllText(f + ".txt"); sc = new scanner1(file_text, writer); int done = sc.scan(); if (done == 0) { label2.Text = "success"; label2.ForeColor = Color.Green; out_no++; } else { label2.Text = "syntax error"; label2.ForeColor = Color.Red; } writer.Close(); } catch { label2.Text = "file does not exist"; label2.ForeColor = Color.Red; writer.Close(); } }
private void Button1_Click(object sender, EventArgs e) { string f = textBox1.Text; try { string output = "output" + out_no.ToString() + ".txt"; writer = new StreamWriter(output); sc = new scanner1(f, writer); int done = sc.scan(); writer.Close(); if (done == 0) { List <string> tokns = new List <string>(); List <string> values = new List <string>(); int counter_of_tokens = 0; string file_text = File.ReadAllText(output); for (int i = 0; i < file_text.Length; i++) { if (i == file_text.Length - 1) { break; } char cur = file_text[i]; string name1 = ""; while (cur != ',') { if (cur != ' ' && cur != '\n' && cur != '\t' && cur != '\r') { name1 += cur; } i++; cur = file_text[i]; } i++; cur = file_text[i]; i++; cur = file_text[i]; string name2 = ""; while (cur != ' ' && cur != '\n' && cur != '\t' && cur != '\r') { if (cur != ' ' && cur != '\n' && cur != '\t' && cur != '\r') { name2 += cur; } i++; cur = file_text[i]; } tokns.Add(name1); values.Add(name2); counter_of_tokens++; } Output form = new Output(tokns, values, counter_of_tokens); form.Show(); Hide(); } else { label2.Text = "syntax error"; label2.ForeColor = Color.Red; } } catch { writer.Close(); } }