Exemple #1
0
    [Test] public void TestRewriteSubtree()
    {
        var ast = new Racr.AstNode(spec, "S", new Racr.AstNode(spec, "A", 42, new Racr.AstNode(spec, "B")));
        var A   = ast.Child("A");
        var B1  = A.Child("B1");

        Assert.IsTrue(A.HasParent());
        Assert.AreEqual(A.NumChildren(), 2);
        Assert.AreEqual(A.NodeType(), "A");
        Assert.AreEqual(A.Child <int>(1), 42);
        Assert.AreEqual(A.Child(2), B1);

        A.RewriteSubtree(new Racr.AstNode(spec, "Aa", 1, new Racr.AstNode(spec, "B"), new Racr.AstNode(spec, "B"), 42));
        Assert.IsFalse(A.HasParent());
        Assert.AreEqual(A.NumChildren(), 2);
        Assert.AreEqual(A.NodeType(), "A");
        Assert.AreEqual(A.Child <int>(1), 42);
        Assert.AreEqual(A.Child(2), B1);

        A = ast.Child("A");
        Assert.IsTrue(A.HasParent());
        Assert.AreEqual(A.NumChildren(), 4);
        Assert.AreEqual(A.NodeType(), "Aa");
        Assert.AreEqual(A.Child <int>(1), 1);
        Assert.AreNotEqual(A.Child(2), B1);
        Assert.AreEqual(A.Child(2).NodeType(), "B");
        Assert.AreEqual(A.Child(3).NodeType(), "B");
        Assert.AreEqual(A.Child <int>(4), 42);
    }
Exemple #2
0
    static void TestRewriteAbstract()
    {
        var spec = new Racr.Specification();

        spec.AstRule("S->A");
        spec.AstRule("A->a");
        spec.AstRule("Aa:A->b-c");
        spec.CompileAstSpecifications("S");
        spec.CompileAgSpecifications();

        var ast = new Racr.AstNode(spec, "S", new Racr.AstNode(spec, "Aa", 1, 2, 3));
        var A   = ast.Child("A");

        Console.WriteLine(A.NumChildren() == 3);
        Console.WriteLine(A.NodeType() == "Aa");

        var c = A.RewriteAbstract("A");

        foreach (var x in c)
        {
            Console.WriteLine(x);
        }

        Console.WriteLine(A.NumChildren() == 1);
        Console.WriteLine(A.NodeType() == "A");
    }
Exemple #3
0
    [Test] public void TestRewriteAbstract()
    {
        var ast = new Racr.AstNode(spec, "S", new Racr.AstNode(spec, "Aa", 1, new Racr.AstNode(spec, "B"), new Racr.AstNode(spec, "B"), 4));
        var A   = ast.Child("A");
        var B1  = A.Child("B1");
        var B2  = A.Child("B2");

        Assert.IsTrue(A.HasParent());
        Assert.AreEqual(A.NumChildren(), 4);
        Assert.AreEqual(A.NodeType(), "Aa");
        Assert.AreEqual(A.Child <int>(1), 1);
        Assert.AreEqual(A.Child(2), B1);
        Assert.AreEqual(A.Child(3), B2);
        Assert.AreEqual(A.Child <int>(4), 4);

        var c = A.RewriteAbstract("A");

        Assert.AreEqual(c.Length, 2);
        Assert.AreEqual(c[0], B2);
        Assert.AreEqual(c[1], 4);

        Assert.IsTrue(A.HasParent());
        Assert.AreEqual(A.NumChildren(), 2);
        Assert.AreEqual(A.NodeType(), "A");
        Assert.AreEqual(A.Child <int>(1), 1);
        Assert.AreEqual(A.Child(2), B1);
    }
Exemple #4
0
    static void TestRewriteRefine()
    {
        var spec = new Racr.Specification();


        spec.AstRule("S->A");
        spec.AstRule("A->a");
        spec.AstRule("Aa:A->b-c");
        spec.CompileAstSpecifications("S");
        spec.CompileAgSpecifications();

        var ast = new Racr.AstNode(spec, "S", new Racr.AstNode(spec, "A", 1));
        var A   = ast.Child("A");

        Console.WriteLine("{0}", A.NumChildren() == 1);
        Console.WriteLine("{0}", A.NodeType() == "A");

        A.RewriteRefine("Aa", 2, 3);

        Console.WriteLine("{0}", A.NumChildren() == 3);
        Console.WriteLine("{0}", A.NodeType() == "Aa");

        foreach (var c in A.Children())
        {
            Console.WriteLine(c);
        }
    }
Exemple #5
0
    static void TestRewriteSubtree()
    {
        var spec = new Racr.Specification();

        spec.AstRule("S->A");
        spec.AstRule("A->a");
        spec.AstRule("Aa:A->b-c");
        spec.CompileAstSpecifications("S");
        spec.CompileAgSpecifications();

        var ast = new Racr.AstNode(spec, "S", new Racr.AstNode(spec, "A", 42));
        var A   = ast.Child("A");

        Console.WriteLine(A.HasParent());
        Console.WriteLine(ast.Child("A").NodeType());

        A.RewriteSubtree(new Racr.AstNode(spec, "Aa", 1, 2, 3));

        Console.WriteLine(A.HasParent());
        Console.WriteLine(ast.Child("A").NodeType());
    }
Exemple #6
0
    // Name Analysis:

    static Ast findL(string name, Ast l, int i)
    {
        for (int j = 1; j <= i; j++)
        {
            var r = l.Child(j).LLookup(name);
            if (r != null)
            {
                return(r);
            }
        }
        return(null);
    }
Exemple #7
0
 public static Ast GetExpression(this Ast n)
 {
     return(n.Child("Expression"));
 }
 public static Racr.AstNode GetDefinitions(this Racr.AstNode n)
 {
     return(n.Child("Definition*"));
 }
Exemple #9
0
 public static string GetName(this Ast n)
 {
     return(n.Child <string>("name"));
 }
Exemple #10
0
 public static Racr.AstNode GetOperands(this Racr.AstNode n)
 {
     return(n.Child("Operands"));
 }
Exemple #11
0
 public static Ast GetOperands(this Ast n)
 {
     return(n.Child("Operands"));
 }
Exemple #12
0
 public static string GetName(this Racr.AstNode n)
 {
     return(n.Child <string>("name"));
 }
Exemple #13
0
 public static ValueTypes GetValueType(this Racr.AstNode n)
 {
     return(n.Child <ValueTypes>("type"));
 }
Exemple #14
0
 public static Racr.AstNode GetList(this Racr.AstNode n)
 {
     return(n.Child("List"));
 }
Exemple #15
0
 public static string GetLabel(this Ast n)
 {
     return(n.Child <string>("label"));
 }
Exemple #16
0
	static void TestRewriteSubtree() {
		var spec = new Racr.Specification();

		spec.AstRule("S->A");
		spec.AstRule("A->a");
		spec.AstRule("Aa:A->b-c");
		spec.CompileAstSpecifications("S");
		spec.CompileAgSpecifications();

		var ast = new Racr.AstNode(spec, "S", new Racr.AstNode(spec, "A", 42));
		var A = ast.Child("A");

		Console.WriteLine(A.HasParent());
		Console.WriteLine(ast.Child("A").NodeType());

		A.RewriteSubtree(new Racr.AstNode(spec, "Aa", 1, 2, 3));

		Console.WriteLine(A.HasParent());
		Console.WriteLine(ast.Child("A").NodeType());
	}
Exemple #17
0
 public static Types GetValueType(this Ast n)
 {
     return(n.Child <Types>("type"));
 }
Exemple #18
0
	static void TestRewriteAbstract() {
		var spec = new Racr.Specification();

		spec.AstRule("S->A");
		spec.AstRule("A->a");
		spec.AstRule("Aa:A->b-c");
		spec.CompileAstSpecifications("S");
		spec.CompileAgSpecifications();

		var ast = new Racr.AstNode(spec, "S", new Racr.AstNode(spec, "Aa", 1, 2, 3));
		var A = ast.Child("A");

		Console.WriteLine(A.NumChildren() == 3);
		Console.WriteLine(A.NodeType() == "Aa");

		var c = A.RewriteAbstract("A");
		foreach (var x in c) Console.WriteLine(x);

		Console.WriteLine(A.NumChildren() == 1);
		Console.WriteLine(A.NodeType() == "A");

	}
Exemple #19
0
	static void TestRewriteRefine() {
		var spec = new Racr.Specification();


		spec.AstRule("S->A");
		spec.AstRule("A->a");
		spec.AstRule("Aa:A->b-c");
		spec.CompileAstSpecifications("S");
		spec.CompileAgSpecifications();

		var ast = new Racr.AstNode(spec, "S", new Racr.AstNode(spec, "A", 1));
		var A = ast.Child("A");

		Console.WriteLine("{0}", A.NumChildren() == 1);
		Console.WriteLine("{0}", A.NodeType() == "A");

		A.RewriteRefine("Aa", 2, 3);

		Console.WriteLine("{0}", A.NumChildren() == 3);
		Console.WriteLine("{0}", A.NodeType() == "Aa");

		foreach (var c in A.Children()) Console.WriteLine(c);

	}
Exemple #20
0
 public static string GetOperator(this Ast n)
 {
     return(n.Child <string>("operator"));
 }
Exemple #21
0
 // AST Accessors
 public static Racr.AstNode GetBody(this Racr.AstNode n)
 {
     return(n.Child("Body"));
 }
Exemple #22
0
    // AST Accessors:

    public static Ast GetBody(this Ast n)
    {
        return(n.Child("Body"));
    }
Exemple #23
0
 public static Racr.AstNode GetExpression(this Racr.AstNode n)
 {
     return(n.Child("Expression"));
 }
Exemple #24
0
 public static string GetT(this Racr.AstNode n)
 {
     return(n.Child <string>("t"));
 }
Exemple #25
0
 public static string GetLabel(this Racr.AstNode n)
 {
     return(n.Child <string>("label"));
 }
Exemple #26
0
 // accessors
 public static double GetValue(this Racr.AstNode n)
 {
     return(n.Child <double>("value"));
 }
Exemple #27
0
 public static object GetValue(this Racr.AstNode n)
 {
     return(n.Child <object>("value"));
 }
Exemple #28
0
 public static Racr.AstNode GetOp2(this Racr.AstNode n)
 {
     return(n.Child("Op2"));
 }
Exemple #29
0
 public static string GetOperator(this Racr.AstNode n)
 {
     return(n.Child <string>("operator"));
 }
Exemple #30
0
 public static object GetValue(this Ast n)
 {
     return(n.Child <object>("value"));
 }