Ejemplo n.º 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);
    }
Ejemplo n.º 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");
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 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);
        }
    }
Ejemplo n.º 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());
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 7
0
 public static Ast GetExpression(this Ast n)
 {
     return(n.Child("Expression"));
 }
Ejemplo n.º 8
0
 public static Racr.AstNode GetDefinitions(this Racr.AstNode n)
 {
     return(n.Child("Definition*"));
 }
Ejemplo n.º 9
0
 public static string GetName(this Ast n)
 {
     return(n.Child <string>("name"));
 }
Ejemplo n.º 10
0
 public static Racr.AstNode GetOperands(this Racr.AstNode n)
 {
     return(n.Child("Operands"));
 }
Ejemplo n.º 11
0
 public static Ast GetOperands(this Ast n)
 {
     return(n.Child("Operands"));
 }
Ejemplo n.º 12
0
 public static string GetName(this Racr.AstNode n)
 {
     return(n.Child <string>("name"));
 }
Ejemplo n.º 13
0
 public static ValueTypes GetValueType(this Racr.AstNode n)
 {
     return(n.Child <ValueTypes>("type"));
 }
Ejemplo n.º 14
0
 public static Racr.AstNode GetList(this Racr.AstNode n)
 {
     return(n.Child("List"));
 }
Ejemplo n.º 15
0
 public static string GetLabel(this Ast n)
 {
     return(n.Child <string>("label"));
 }
Ejemplo n.º 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());
	}
Ejemplo n.º 17
0
 public static Types GetValueType(this Ast n)
 {
     return(n.Child <Types>("type"));
 }
Ejemplo n.º 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");

	}
Ejemplo n.º 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);

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

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