Evaluate() public method

public Evaluate ( ) : void
return void
Esempio n. 1
0
 static void Main(string[] args)
 {
     var grammar = new ExampleExpressionGrammar();
     var interpriter = new ScriptInterpreter(grammar);
     interpriter.Evaluate("circle 4,53 123\ncircle 2,4 12");
     if(interpriter.Status != InterpreterStatus.Ready)
     {
         throw new InvalidOperationException("You syntax errored!?");
     }
     var program = interpriter.ParsedScript.Root.AstNode as StatementListNode;
     foreach (var circle in program.ChildNodes.OfType<CircleDefNode>())
     {
         Console.WriteLine("I saw a circle at ({0},{1}) with a radius {2}",
             circle.Point.X,
             circle.Point.Y,
             circle.Radius);
     }
     Console.ReadKey();
 }
Esempio n. 2
0
        public IEnumerable<Project> Interpret(string dslText)
        {
            List<Project> projects = new List<Project>();
            var grammar = new ProjectsGrammar();
            var interpriter = new ScriptInterpreter(grammar);
            interpriter.Evaluate(dslText);
            if (interpriter.Status != InterpreterStatus.Ready)
            {
                throw new InvalidOperationException("Your syntax errored!?");
            }

            var program = interpriter.ParsedScript.Root.AstNode as StatementListNode;
            foreach (var node in program.ChildNodes)
            {
                if (node.Term.Name == "Project")
                {
                    var projectName = (LiteralValueNode) node.ChildNodes[0];
                    var project = new Project(projectName.Value.ToString().Trim());
                    projects.Add(project);
                    var notes = (StatementListNode) node.ChildNodes[1];
                    foreach(var note in notes.ChildNodes)
                    {
                        project.AddNote(((LiteralValueNode) note).Value.ToString().Trim());
                    }

                    var tasks = (StatementListNode)node.ChildNodes[2];
                    foreach (var child in tasks.ChildNodes)
                    {
                        var taskName = (LiteralValueNode)child.ChildNodes[0];
                        var task = new TaskItem(taskName.Value.ToString());
                        projects.Last().AddTask(task);
                        var taskNotes = (StatementListNode)child.ChildNodes[1];
                        foreach (var note in taskNotes.ChildNodes)
                        {
                            task.AddNote(((LiteralValueNode)note).Value.ToString().Trim());
                        }
                    }
                }
            }
            return projects;
        }
Esempio n. 3
0
 //This method allows custom implementation of running a sample in Grammar Explorer
 // By default it evaluates a parse tree using default interpreter
 public virtual string RunSample(ParseTree parsedSample)
 {
     var interpreter = new ScriptInterpreter(this);
       interpreter.Evaluate(parsedSample);
       return interpreter.GetOutput();
 }