static void writeToFile() { //string[] arr = new string[Classification.tokenList.Count+3]; string a = ""; string path = @"C:\Users\Nouman Ejaz\Desktop\tokens.txt"; Classification c2 = new Classification(); c2.switch_case(); StreamWriter sw = new StreamWriter(path); foreach (var token in Classification.tokenList) { sw.WriteLine("Line Number: {0} Class Keyword: {1} Value Part: {2}", token.lineNumber, token.classKeyword, token.value); a += "Line Number: " + token.lineNumber + " Class Keyword: " + token.classKeyword + " Value: " + token.value + "\n \n"; } sw.Close(); System.Diagnostics.Process.Start("notepad", path); //MessageBox.Show("Compilation Completed"); }
public void switch_case() { string test = ""; string firstWord = ""; Classification c1 = new Classification(); foreach (var token in Classification.tokenList) { firstWord = token.value[0].ToString(); if (char.IsDigit(token.value[0])) { firstWord = "num"; } switch (firstWord) { case "+": case "-": case ".": case "num": if (c1.isInt(token.value)) { token.classKeyword = "int_const"; } else if (c1.isFloat(token.value)) { token.classKeyword = "float_const"; } else { token.classKeyword = getClass(token.value); } break; case "\"": if (c1.isString(token.value)) { token.classKeyword = "string_const"; } else { token.classKeyword = "Invalid"; } break; case "\'": if (c1.isChar(token.value)) { token.classKeyword = "char_const"; } else { token.classKeyword = "Invalid"; } break; case "_": if (c1.isIdentifier(token.value)) { token.classKeyword = "ID"; } else { token.classKeyword = "Invalid"; } break; default: token.classKeyword = c1.getClass(token.value); break; } } }