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); } }
public void Init() { Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); _lexer = new Lexer(Path.Combine("Data", "FnSampleLexis.xml")) { YieldEndOfSource = true }; _parser = new Parser(Path.Combine("Data", "FnSampleGrammar.xml")); }