/// <summary> /// Reads the Mini-PL source code and executes it. /// </summary> /// <param name="args">File name or path/fileName</param> public static void Main(string[] args) { if ( args.Length < 1 ) { Console.WriteLine("You must give a file name or a path/fileName as a parameter"); return; } if ( args.Length > 1 ) { Console.WriteLine("Too many parameters"); return; } var fileReader = new FileReader(FileExtension); try { var lines = fileReader.ReadFile(args[0]); var scanner = new Scanner(); var tokens = scanner.Tokenize(lines); var parser = new Parser(); var tree = parser.Parse(tokens); tree.Execute(); } catch(AssertFailedException) { // Code had an assert statement, which failed } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); } }
protected void SetUp() { _scanner = new Scanner(); _parser = new Parser(); Statement.DeleteAllVariables(); Statements.ClearErrors(); }
protected void SetUp() { var scanner = new Scanner(); _parser = new Parser(); _correctSourceCodes = new[] { new List<string> { "var nTimes : int := 0;", "var s : string := \"How many times?\";", "print s;", "read nTimes;", "var x : int;", "x := 0;", "for x in 0..nTimes-1 do ", " print x;", " print \" : Hello, World!\\n\";", "end for;", "var b : bool := x = nTimes;", "assert (b);" }, new List<string> { "var x : int;", "var y : bool;", "var z : string;", }, new List<string> { "var x : int := (4 + (6 * 2))/(2-0);", "var y : bool := !true & true;", "var z : bool := 3 < 2;", "assert(x > 2);", "assert(3 >= 2);", "assert(x <= 12);", "assert(x = 8);", }, new List<string> { "var x : int := (4 + (6 * 2))/(2-0);", "var y : bool := !true & true;", "var z : bool := 3 < 2;", "assert(x > 2);", "assert(3 >= 2);", "assert(x <= 12);", "assert(x = 8);", "for x in 0..5*4 do", "print x;", "end for;", "read x;" }, new List<string> { "var x : int := 3;", "var y2k : bool := true;", "var CONSTANT_TEST : string := \"test\";", "assert(x > 2);", "assert(y2k != false);", "assert(CONSTANT_TEST = \"test\");" }, new List<string> { "var i : int; // := 0;", "//var s : string := \"How many times?\";", "var b : bool := true;", }, new List<string> { "var i : int; /* := 0;", "//var s : string := \"How many times?\";*/", "var b : bool := true;", }}; _correctSourceCodeTokens = new List<Token>[_correctSourceCodes.Length]; for (var i = 0; i < _correctSourceCodeTokens.Length; i++) { _correctSourceCodeTokens[i] = scanner.Tokenize(_correctSourceCodes[i]); } }