public override object Visit(AstNode node) {
     var result = node.Accept(this);
     VisitChildren(node);
     return result;
 }
 private EvaluationResult Evaluate(AstNode node) {
     return (EvaluationResult)this.Visit(node);
 }
 public IEnumerable<ErrorAstNode> Collect(AstNode root) {
     this.Visit(root);
     return _errors;
 }
Exemple #4
0
 public virtual object VisitChildren(AstNode node) {
     return node.Children.Aggregate<AstNode, object>(null, (prev, child) => Visit(child));
 }
Exemple #5
0
 public virtual object Visit(AstNode node) {
     return node.Accept(this);
 }
Exemple #6
0
        private void CheckExpression(AstNode astNode, int indent, object[] objects, ref int index) {
            var exprName = (string)objects[index++];
            Type type = null;
            switch (exprName) {
                case "const":
                    type = typeof(ConstantAstNode);
                    break;
                case "binop":
                    type = typeof(BinaryAstNode);
                    break;
                case "unop":
                    type = typeof(UnaryAstNode);
                    break;
                case "call":
                    type = typeof(MethodCallAstNode);
                    break;
                case "error":
                    type = typeof(ErrorAstNode);
                    break;
                default:
                    throw new InvalidOperationException(string.Format("Test error: unrecognized expression type abbreviation '{0}'", exprName));
            }

            Trace.WriteLine(string.Format("{0}: {1}{2} (Current: {3})", indent, new string(' ', indent * 2), type.Name, astNode));

            Assert.That(astNode.GetType(), Is.EqualTo(type));

            if (exprName == "const") {
                Assert.That((astNode as ConstantAstNode).Value, Is.EqualTo(objects[index++]));
            }
            else if (exprName == "binop") {
                Assert.That((astNode as BinaryAstNode).Operator.Kind, Is.EqualTo(objects[index++]));
            }
            else if (exprName == "unop") {
                Assert.That((astNode as UnaryAstNode).Operator.Kind, Is.EqualTo(objects[index++]));
            }
            else if (exprName == "call") {
                Assert.That((astNode as MethodCallAstNode).Token.Kind, Is.EqualTo(objects[index++]));
                Assert.That((astNode as MethodCallAstNode).Token.Value, Is.EqualTo(objects[index++]));
            }

            foreach (var child in astNode.Children) {
                CheckExpression(child, indent + 1, objects, ref index);
            }
        }
Exemple #7
0
 public UnaryAstNode(Token token, AstNode operand) {
     _operand = operand;
     _token = token;
 }
Exemple #8
0
 public BinaryAstNode(AstNode left, Token token, AstNode right) {
     _left = left;
     _token = token;
     _right = right;
 }