public void TestAddListToExistChildren() { // Add child ^(nil 101 102 103) to root ^(5 6) // should add 101 102 103 to end of 5's child list CommonTree root = new CommonTree( new CommonToken( 5 ) ); root.AddChild( new CommonTree( new CommonToken( 6 ) ) ); // child tree CommonTree r0 = new CommonTree( (IToken)null ); CommonTree c0, c1, c2; r0.AddChild( c0 = new CommonTree( new CommonToken( 101 ) ) ); r0.AddChild( c1 = new CommonTree( new CommonToken( 102 ) ) ); r0.AddChild( c2 = new CommonTree( new CommonToken( 103 ) ) ); root.AddChild( r0 ); assertNull( root.Parent ); assertEquals( -1, root.ChildIndex ); // check children of root all point at root assertEquals( root, c0.Parent ); assertEquals( 1, c0.ChildIndex ); assertEquals( root, c0.Parent ); assertEquals( 2, c1.ChildIndex ); assertEquals( root, c0.Parent ); assertEquals( 3, c2.ChildIndex ); }
// method xyt(param1, param2) { public UserFunction(String name, List<String> parameterNames, CommonTree functionBody, int definedLine) { this.parameterNames = parameterNames; this.functionBody = functionBody; this.name = name; this.definedLine = definedLine; }
private SnapshotSpan? GetSpan(CommonTree tree) { if (tree == null) return null; return GetSpan(tree.Token); }
public AstNode BindToAntlrNode(CommonTree node) { // horrible, but works for now if (AntlrNode == null) AntlrNode = node; return this; }
public BlaiseInstrumentTreeWalker(CommonTree tree, CommonTokenStream tokens, BlaiseImportOptions options, string agencyId, string mainLanguage) { this.tree = tree; this.tokens = tokens; this.options = options; this.MainLanguage = mainLanguage; this.AgencyId = agencyId; Result = new XDocument(); DdiInstance = Ddi.Element(Ddi.DdiInstance); Ddi.AddNamespaces(DdiInstance); ResourcePackage = Ddi.Element(Ddi.ResourcePackage); // Required in DDI 3.1 var purpose = Ddi.Element(Ddi.Purpose); purpose.Add(Ddi.XmlLang(MainLanguage)); purpose.Add(new XElement(Ddi.Content, "Not Specified")); ResourcePackage.Add(purpose); Instrument = Ddi.Element(Ddi.Instrument); ControlConstructScheme = Ddi.Element(Ddi.ControlConstructScheme); XElement groupDataCollection = Ddi.Element(Ddi.GroupDataCollection, false); XElement dataCollection = Ddi.Element(Ddi.DataCollection); groupDataCollection.Add(dataCollection); dataCollection.Add(Instrument); ResourcePackage.Add(groupDataCollection); ResourcePackage.Add(ControlConstructScheme); DdiInstance.Add(ResourcePackage); }
public CommonTree(CommonTree node) : base(node) { this.token = node.token; this.startIndex = node.startIndex; this.stopIndex = node.stopIndex; }
private object Add(CommonTree tree) { var lhs = LhsOperand(tree); var rhs = RhsOperand(tree); return Operator.Add(lhs, rhs); }
public void TestSeek() { // ^(101 ^(102 103 ^(106 107) ) 104 105) // stream has 7 real + 6 nav nodes // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF ITree r0 = new CommonTree( new CommonToken( 101 ) ); ITree r1 = new CommonTree( new CommonToken( 102 ) ); r0.AddChild( r1 ); r1.AddChild( new CommonTree( new CommonToken( 103 ) ) ); ITree r2 = new CommonTree( new CommonToken( 106 ) ); r2.AddChild( new CommonTree( new CommonToken( 107 ) ) ); r1.AddChild( r2 ); r0.AddChild( new CommonTree( new CommonToken( 104 ) ) ); r0.AddChild( new CommonTree( new CommonToken( 105 ) ) ); ITreeNodeStream stream = newStream( r0 ); stream.Consume(); // consume 101 stream.Consume(); // consume DN stream.Consume(); // consume 102 stream.Seek( 7 ); // seek to 107 Assert.AreEqual( 107, ( (ITree)stream.LT( 1 ) ).Type ); stream.Consume(); // consume 107 stream.Consume(); // consume UP stream.Consume(); // consume UP Assert.AreEqual( 104, ( (ITree)stream.LT( 1 ) ).Type ); }
public void generateFile(CommonTree ast, string fileName) { using (XmlWriter writer = XmlWriter.Create(fileName)) { generate(ast, writer); } }
public int CountAltsForRule( CommonTree t ) { CommonTree block = (CommonTree)t.GetFirstChildWithType(BLOCK); if (block == null || block.ChildCount == 0) return 0; return block.Children.Count(i => i.Type == ALT); }
protected void WalkChildren(CommonTree ast) { if (ast == null || ast.Children == null) return; foreach (CommonTree child in ast.Children) Walk(child); }
public static List<Expression> Extract(CommonTree tree) { var list = new List<Expression>(); if (tree.Children == null) return list; list.AddRange(tree.Children.Select(arg => new Expression(arg))); return list; }
protected override void HandleSignature(CommonTree signature, IList<IToken> qualifiers, IList<CommonTree> names, CommonTree extendsSpec, CommonTree body, CommonTree block) { if (names == null) return; foreach (var name in names) HandleSignatureOrEnum(signature, name); }
public CommonTree(CommonTree node) : base(node) { if (node == null) throw new ArgumentNullException("node"); this.token = node.token; this.startIndex = node.startIndex; this.stopIndex = node.stopIndex; }
public XmlDocument generateDocument(CommonTree ast) { XmlDocument doc = new XmlDocument(); using (XmlWriter writer = doc.CreateNavigator().AppendChild()) { generate(ast, writer); } return doc; }
//Даний метод розпочинає обхід AST з кореня public string VisitProgram(CommonTree tree) { //Початок обходу дітей кореневого вузла foreach (CommonTree node in tree.Children.OfType<CommonTree>()) { switch (node.Type) { case Y11Parser.BECOMES: this.VisitAssign(node);//Якщо операція присвоєння break; case Y11Parser.GET: this.VisitInput(node);//Якщо операція вводу break; case Y11Parser.PUT: this.VisitOutput(node);//Якщо операція виводу break; case Y11Parser.VAR: this.VisitInit(node);//Якщо оголошення змінних break; case Y11Parser.REP: this.VisitCycle(node);//Якщо початок циклу break; default: break; } } program.AppendFormat(".assembly {0} ", AName); program.AppendLine("{}"); program.AppendLine(".assembly extern mscorlib {}"); program.AppendLine(".method static void main()"); program.AppendLine("{"); program.AppendLine(".entrypoint"); program.AppendLine(".maxstack 100"); if (this.Variables.Count > 0) { string variableString = "int32 " + this.Variables.First(); foreach (string name in this.Variables.Skip(1)) { variableString += ", int32 " + name; } program.AppendFormat(".locals init ({0}) \n", variableString); } program.Append(this.methodBody.ToString()); program.AppendLine("call string [mscorlib]System.Console::ReadLine()"); program.AppendLine("ret"); program.AppendLine("}"); return program.ToString(); }
// Expected tree for function: ^(FUNC ID ( INT | ID ) expr) /** Set up a local evaluator for a nested function call. The evaluator gets the definition * tree of the function; the set of all defined functions (to find locally called ones); a * pointer to the global variable memory; and the value of the function parameter to be * added to the local memory. */ private DebugTreeGrammar(CommonTree function, List<CommonTree> functionDefinitions, IDictionary<string, BigInteger> globalMemory, BigInteger paramValue) : this(new CommonTreeNodeStream(function.GetChild(2)), functionDefinitions) { this.globalMemory = globalMemory; localMemory[function.GetChild(1).Text] = paramValue; }
void Walk(CommonTree tree) { if (tree.IsFunction()) { AddMethod(tree); } if (tree.HasChildren()) { WalkChildren(tree.Children); } }
private static int getLastTreePosition(CommonTree tree) { IList children = tree.Children; if (children == null) { return ((CommonToken)tree.Token).StopIndex + 1; } return getLastTreePosition((CommonTree)children[children.Count - 1]); }
private static IToken getFirstTreeToken(CommonTree tree) { IList children = tree.Children; if (children == null) { return tree.Token; } return getFirstTreeToken((CommonTree)children[0]); }
/** Set up a local evaluator for a nested function call. The evaluator gets the definition * tree of the function; the set of all defined functions (to find locally called ones); a * pointer to the global variable memory; and the value of the function parameter to be * added to the local memory. */ private ProfileTreeGrammar(CommonTree function, List<CommonTree> functionDefinitions, IDictionary<string, BigInteger> globalMemory, BigInteger paramValue) // Expected tree for function: ^(FUNC ID ( INT | ID ) expr) : this(new CommonTreeNodeStream(function.GetChild(2)), functionDefinitions) { this.globalMemory = globalMemory; localMemory[function.GetChild(1).Text] = paramValue; }
public Method(String id, String type, CommonTree identifiers, CommonTree block) { this.id = id; this.returnType = type; this.identTypes = ToList(identifiers,0); this.identifiers = ToList(identifiers,1); code = block; scope = new Scope(); Console.WriteLine("identifiers: " + this.identifiers.Count); }
public Method(Method original) { // Used for recursively calling methods id = original.id; returnType = original.returnType; identTypes = original.identTypes; identifiers = original.identifiers; code = original.code; scope = original.scope.Copy(); }
public void EmitAssignArray(IToken token, CommonTree tree) { var index = 0; var asgnNode = (CommonTree) tree.Parent; foreach (var item in asgnNode.Children) { function.Add(AsmTemplate.AssignIndex(token.Text, int.Parse(item.Text), index++)); MapFunction(token); } }
public void Test4Nodes() { // ^(101 ^(102 103) 104) CommonTree r0 = new CommonTree( new CommonToken( 101 ) ); r0.AddChild( new CommonTree( new CommonToken( 102 ) ) ); r0.GetChild( 0 ).AddChild( new CommonTree( new CommonToken( 103 ) ) ); r0.AddChild( new CommonTree( new CommonToken( 104 ) ) ); assertNull( r0.Parent ); assertEquals( -1, r0.ChildIndex ); }
public JavaDebugExpression(JavaDebugExpressionContext context, CommonTree expression, string expressionText) { Contract.Requires<ArgumentNullException>(context != null, "context"); Contract.Requires<ArgumentNullException>(expression != null, "expression"); Contract.Requires<ArgumentNullException>(expressionText != null, "expressionText"); Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(expressionText)); _context = context; _expression = expression; _expressionText = expressionText; }
public string generateString(CommonTree ast) { using (var sw = new StringWriter()) { using (var writer = XmlWriter.Create(sw)) { generate(ast, writer); } return sw.ToString(); } }
/// <summary> /// Set up a local evaluator for a nested function call. The evaluator gets the definition /// tree of the function; the set of all defined functions (to find locally called ones); a /// pointer to the global variable memory; and the value of the function parameter to be /// added to the local memory. /// </summary> /// <param name="function"></param> /// <param name="functionDefinitions"></param> /// <param name="globalMemory"></param> /// <param name="paramValue"></param> private FunctionalTreeParser( CommonTree function, IList<CommonTree> functionDefinitions, IDictionary<string, BigInteger> globalMemory, BigInteger paramValue) : this(// Expected tree for function: ^(FUNC ID ( INT | ID ) expr) new CommonTreeNodeStream(function.GetChild(2)), functionDefinitions) { //this.globalMemory = globalMemory; this.localMemory.Add(function.GetChild(1).Text, paramValue); }
private static int getFirstTreePosition(CommonTree tree) { if (tree == null) return -1; IList children = tree.Children; if (children == null) { return ((CommonToken)tree.Token).StartIndex; } return getFirstTreePosition((CommonTree)children[0]); }
private static IToken getLastTreeToken(CommonTree tree) { if (tree == null) return null; IList children = tree.Children; if (children == null) { return tree.Token; } return getLastTreeToken((CommonTree)children[children.Count - 1]); }
public void Test_opencyclemap() { //TODO: this css will not parse; the meta section is a problem! // parses the MapCSS. AstParserRuleReturnScope <object, IToken> result = this.TestMapCSSParsing( "OsmSharp.UI.Test.Unittests.Data.MapCSS.opencyclemap.mapcss"); // Test the very minimum; no errors during parsing says a lot already! Antlr.Runtime.Tree.CommonTree tree = result.Tree as Antlr.Runtime.Tree.CommonTree; Assert.NotNull(tree); Assert.AreEqual(47, tree.ChildCount); }