Ejemplo n.º 1
0
        public Dictionary <string, Object> Evaluate(String text, int numInstructions)
        {
            ParseTree parseTree = parser.Parse(text);

            if (parseTree.Root != null)
            {
                Console.WriteLine("Time To Parse {0} instructions: {1} ms", numInstructions, parseTree.ParseTimeMilliseconds);
                PowerPCTreeEvaluator app = new PowerPCTreeEvaluator();
                var startTime            = System.Environment.TickCount;
                app.Evaluate(parseTree, Instance);
                var endTime = System.Environment.TickCount - startTime;
                Console.WriteLine("Time to execute {0} instructions: {1} ms", numInstructions, endTime);
                return(new Dictionary <string, object> {
                    { "parse_time", parseTree.ParseTimeMilliseconds },
                    { "execution_time", endTime },
                    { "status", "ok" }
                });
            }
            var errorToken = parseTree.Tokens.Where(n => n.Terminal.Name == "SYNTAX_ERROR").FirstOrDefault();

            return(new Dictionary <string, object> {
                { "status", "error" },
                { "error_message", parseTree.ParserMessages[0] },
                { "error_location", errorToken == null ? new SourceLocation(0, -1, -1) : errorToken.Location }
            });
        }
Ejemplo n.º 2
0
 public Dictionary<string, Object> Evaluate(String text, int numInstructions)
 {
     ParseTree parseTree = parser.Parse(text);
     if (parseTree.Root != null)
     {
         Console.WriteLine("Time To Parse {0} instructions: {1} ms", numInstructions, parseTree.ParseTimeMilliseconds);
         PowerPCTreeEvaluator app = new PowerPCTreeEvaluator();
         var startTime = System.Environment.TickCount;
         app.Evaluate(parseTree, Instance);
         var endTime = System.Environment.TickCount - startTime;
         Console.WriteLine("Time to execute {0} instructions: {1} ms", numInstructions, endTime);
         return new Dictionary<string, object> {
             { "parse_time", parseTree.ParseTimeMilliseconds },
             { "execution_time", endTime },
             { "status", "ok" }
         };
     }
     var errorToken = parseTree.Tokens.Where(n => n.Terminal.Name == "SYNTAX_ERROR").FirstOrDefault();
     return new Dictionary<string, object> {
         { "status", "error" },
         { "error_message", parseTree.ParserMessages[0] },
         { "error_location", errorToken == null ? new SourceLocation(0, -1, -1) : errorToken.Location }
     };
 }