static void Main(string[] args) { if (args.Length == 0) Console.WriteLine("Program parameter: input file path"); else try { using (var streamReader = File.OpenText(args[0])) { var scanner = new Scanner(); var tokenString = scanner.Scan(streamReader.ReadToEnd()); var identifiers = scanner.identifiers.Keys.Except(Scanner.Keywords); var constants = scanner.constants.Keys; var relationTable = new RelationTable(identifiers, constants); var tree = new Parser(relationTable).Parse(tokenString); var codeGenerator = new CodeGenerator(); var assembly = codeGenerator.ColdFire(tree); Console.WriteLine(assembly); } } catch (FileNotFoundException) { Console.WriteLine("File not found"); } catch (IOException e) { Console.WriteLine(e.Message); } catch (LexicalException e) { Console.WriteLine(e.Message); } catch (SyntaxException e) { Console.WriteLine(e.Message); } catch (SemanticException e) { Console.WriteLine(e.Message); } catch (RelationException<string, Relation> e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { if (args.Length == 0) MessageBox.Show("Program parameter: input file path", "Help", MessageBoxButtons.OK, MessageBoxIcon.Information); else try { using (var streamReader = File.OpenText(args[0])) { var scanner = new Scanner(); var tokenString = scanner.Scan(streamReader.ReadToEnd()); var identifiers = scanner.identifiers.Keys.Except(Scanner.Keywords); var constants = scanner.constants.Keys; var relationTable = new RelationTable(identifiers, constants); var tree = new Parser(relationTable).Parse(tokenString); Application.Run(new TreeViewer(tree)); } } catch (FileNotFoundException) { MessageBox.Show("File not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (IOException e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (LexicalException e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (SyntaxException e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (RelationException<string, Relation> e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
static void Main(string[] args) { if (args.Length == 0) Console.WriteLine("Program parameter: input file path"); else try { using (var streamReader = File.OpenText(args[0])) { var text = streamReader.ReadToEnd(); var scanner = new Scanner(); Console.WriteLine("Program output token string:\n" + scanner.Scan(text).Aggregate("", (sum, next) => sum + next.Item1 + ' ')); Console.WriteLine("\nTable of identifiers:"); foreach (var pair in scanner.identifiers) Console.WriteLine("{0}\t{1}", pair.Value, pair.Key); Console.WriteLine("\nTable of numerical constants:"); foreach (var pair in scanner.constants) Console.WriteLine("{0}\t{1}", pair.Value, pair.Key); Console.WriteLine("\nTable of long delimiters:"); foreach (var pair in scanner.longDelimiters) Console.WriteLine("{0}\t{1}", pair.Value, pair.Key); Console.WriteLine(); } } catch (FileNotFoundException) { Console.WriteLine("File not found"); } catch (IOException e) { Console.WriteLine(e.Message); } catch (LexicalException e) { Console.WriteLine(e.Message); } }