static void Main(string[] args) { if (args.Length == 1) { debug = false; } switch (args.Length) { case 0: Console.WriteLine("Specify a file path."); break; default: FileStream fs; try { fs = System.IO.File.OpenRead(args[0]); } catch (Exception e) { Console.WriteLine(e.Message); break; } MiniPL miniPL = MiniPL.GetInstance(); Scanner sc = miniPL.Scanner; Parser ps = miniPL.Parser; ParseTree ptree = ps.Parse(sc.Tokenize(fs)); MiniPL.Runnable prog = miniPL.ProcessParseTree(ptree, ps.Errors, ps.IsValidParseTree); prog.Execute(Console.In, Console.Out); break; } }
private List <Error> GetErrors(string program) { MiniPL miniPL = MiniPL.GetInstance(); Scanner sc = miniPL.Scanner; Parser ps = miniPL.Parser; ParseTree ptree = ps.Parse(sc.Tokenize(program)); MiniPL.Runnable prog = miniPL.ProcessParseTree(ptree, ps.Errors, ps.IsValidParseTree); return(prog.errors); }
private string RunWithInput(string program, string input) { MiniPL miniPL = MiniPL.GetInstance(); Scanner sc = miniPL.Scanner; Parser ps = miniPL.Parser; ParseTree ptree = ps.Parse(sc.Tokenize(program)); MiniPL.Runnable prog = miniPL.ProcessParseTree(ptree, ps.Errors, ps.IsValidParseTree); StringWriter writer = new StringWriter(); StringReader reader = new StringReader(input); prog.Execute(reader, writer); return(writer.ToString()); }
public void Semantics_DeclarationScanTest() { string text = "print \"Give a number\";\n" + "var n : int;\n" + "read n;\n" + "var f : int := 1;\n" + "var i : int;\n" + "for i in 1..n do\n" + " f := f * i;\n" + "end for;\n" + "print \"The result is: \";\n" + "print f;"; MiniPL miniPL = MiniPL.GetInstance(); Scanner sc = miniPL.Scanner; Parser ps = miniPL.Parser; ParseTree ptree = ps.Parse(sc.Tokenize(text)); MiniPL.Runnable prog = miniPL.ProcessParseTree(ptree, ps.Errors, ps.IsValidParseTree); Assert.AreEqual(3, prog.declarations.Count); }