[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); }
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"); }
[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); }
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); } }
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()); }
// 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); }
public static Ast GetExpression(this Ast n) { return(n.Child("Expression")); }
public static Racr.AstNode GetDefinitions(this Racr.AstNode n) { return(n.Child("Definition*")); }
public static string GetName(this Ast n) { return(n.Child <string>("name")); }
public static Racr.AstNode GetOperands(this Racr.AstNode n) { return(n.Child("Operands")); }
public static Ast GetOperands(this Ast n) { return(n.Child("Operands")); }
public static string GetName(this Racr.AstNode n) { return(n.Child <string>("name")); }
public static ValueTypes GetValueType(this Racr.AstNode n) { return(n.Child <ValueTypes>("type")); }
public static Racr.AstNode GetList(this Racr.AstNode n) { return(n.Child("List")); }
public static string GetLabel(this Ast n) { return(n.Child <string>("label")); }
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()); }
public static Types GetValueType(this Ast n) { return(n.Child <Types>("type")); }
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"); }
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); }
public static string GetOperator(this Ast n) { return(n.Child <string>("operator")); }
// AST Accessors public static Racr.AstNode GetBody(this Racr.AstNode n) { return(n.Child("Body")); }
// AST Accessors: public static Ast GetBody(this Ast n) { return(n.Child("Body")); }
public static Racr.AstNode GetExpression(this Racr.AstNode n) { return(n.Child("Expression")); }
public static string GetT(this Racr.AstNode n) { return(n.Child <string>("t")); }
public static string GetLabel(this Racr.AstNode n) { return(n.Child <string>("label")); }
// accessors public static double GetValue(this Racr.AstNode n) { return(n.Child <double>("value")); }
public static object GetValue(this Racr.AstNode n) { return(n.Child <object>("value")); }
public static Racr.AstNode GetOp2(this Racr.AstNode n) { return(n.Child("Op2")); }
public static string GetOperator(this Racr.AstNode n) { return(n.Child <string>("operator")); }
public static object GetValue(this Ast n) { return(n.Child <object>("value")); }