Example #1
0
		public virtual void resetState()
		{
			traceDepth  = 0;
			returnAST	= null;
			retTree_	= null;
			inputState.reset();
		}
Example #2
0
 /*Make sure current lookahead symbol matches the given set
  * Throw an exception upon mismatch, which is catch by either the
  * error handler or by the syntactic predicate.
  */
 public virtual void  match(AST t, BitSet b)
 {
     if (t == null || t == ASTNULL || !b.member(t.Type))
     {
         throw new MismatchedTokenException(getTokenNames(), t, b, false);
     }
 }
Example #3
0
        /// <summary>
        /// Creates and initializes a new AST node using the specified Token Type ID.
        /// The <see cref="System.Type"/> used for creating this new AST node is
        /// determined by the following:
        /// <list type="bullet">
        ///		<item>the current TokenTypeID-to-ASTNodeType mapping (if any) or,</item>
        ///		<item>the <see cref="defaultASTNodeTypeObject_"/> otherwise</item>
        /// </list>
        /// </summary>
        /// <param name="type">Token type ID to be used to create new AST Node.</param>
        /// <returns>An initialized AST node object.</returns>
        public virtual AST create(int type)
        {
            AST newNode = createFromNodeType(type);

            newNode.initialize(type, "");
            return(newNode);
        }
Example #4
0
 /// <summary>
 /// Add a child to the current AST
 /// </summary>
 /// <param name="currentAST">The AST to add a child to</param>
 /// <param name="child">The child AST to be added</param>
 public virtual void  addASTChild(ref ASTPair currentAST, AST child)
 {
     if (child != null)
     {
         if (currentAST.root == null)
         {
             // Make new child the current root
             currentAST.root = child;
         }
         else
         {
             if (currentAST.child == null)
             {
                 // Add new child to current root
                 currentAST.root.setFirstChild(child);
             }
             else
             {
                 currentAST.child.setNextSibling(child);
             }
         }
         // Make new child the current child
         currentAST.child = child;
         currentAST.advanceChildToEnd();
     }
 }
Example #5
0
        /// <summary>
        /// Creates a new AST node using the specified AST Node Type name. Once created,
        /// the new AST node is initialized with the specified Token type ID and string.
        /// The <see cref="System.Type"/> used for creating this new AST node is
        /// determined solely by <c>ASTNodeTypeName</c>.
        /// The AST Node type must have a default/parameterless constructor.
        /// </summary>
        /// <param name="type">Token type ID to be used to create new AST Node.</param>
        /// <param name="txt">Text for initializing the new AST Node.</param>
        /// <param name="ASTNodeTypeName">Fully qualified name of the Type to be used for creating the new AST Node.</param>
        /// <returns>An initialized AST node object.</returns>
        public virtual AST create(int type, string txt, string ASTNodeTypeName)
        {
            AST newNode = createFromNodeName(ASTNodeTypeName);

            newNode.initialize(type, txt);
            return(newNode);
        }
Example #6
0
        /// <summary>
        /// Creates a new AST node using the specified AST Node Type name.
        /// </summary>
        /// <param name="tok">Token instance to be used to initialize the new AST Node.</param>
        /// <param name="ASTNodeTypeName">
        ///		Fully qualified name of the Type to be used for creating the new AST Node.
        ///	</param>
        /// <returns>A newly created and initialized AST node object.</returns>
        /// <remarks>
        /// Once created, the new AST node is initialized with the specified Token
        /// instance. The <see cref="System.Type"/> used for creating this new AST
        /// node is  determined solely by <c>ASTNodeTypeName</c>.
        /// <para>The AST Node type must have a default/parameterless constructor.</para>
        /// </remarks>
        public virtual AST create(IToken tok, string ASTNodeTypeName)
        {
            AST newNode = createFromNodeName(ASTNodeTypeName);

            newNode.initialize(tok);
            return(newNode);
        }
Example #7
0
        private AST createFromNodeType(int nodeTypeIndex)
        {
            Debug.Assert((nodeTypeIndex >= 0) && (nodeTypeIndex <= heteroList_.Length), "Invalid AST node type!");
            AST newNode = null;

            FactoryEntry entry = heteroList_[nodeTypeIndex];

            if ((entry != null) && (entry.Creator != null))
            {
                newNode = entry.Creator.Create();
            }
            else
            {
                if ((entry == null) || (entry.NodeTypeObject == null))
                {
                    if (defaultCreator_ == null)
                    {
                        newNode = createFromNodeTypeObject(defaultASTNodeTypeObject_);
                    }
                    else
                    {
                        newNode = defaultCreator_.Create();
                    }
                }
                else
                {
                    newNode = createFromNodeTypeObject(entry.NodeTypeObject);
                }
            }
            return(newNode);
        }
Example #8
0
        /*Is 'sub' a subtree of this list?
         *  The siblings of the root are NOT ignored.
         */
        public virtual bool EqualsListPartial(AST sub)
        {
            AST sibling;

            // the empty tree is always a subset of any tree.
            if (sub == null)
            {
                return(true);
            }

            // Otherwise, start walking sibling lists.  First mismatch, return false.
            for (sibling = this; sibling != null && sub != null; sibling = sibling.getNextSibling(), sub = sub.getNextSibling())
            {
                // as a quick optimization, check roots first.
                if (!sibling.Equals(sub))
                {
                    return(false);
                }
                // if roots match, do partial list match test on children.
                if (sibling.getFirstChild() != null)
                {
                    if (!sibling.getFirstChild().EqualsListPartial(sub.getFirstChild()))
                    {
                        return(false);
                    }
                }
            }
            if (sibling == null && sub != null)
            {
                // nothing left to match in this tree, but subtree has more
                return(false);
            }
            // either both are null or sibling has more, but subtree doesn't
            return(true);
        }
Example #9
0
 public virtual void resetState()
 {
     traceDepth = 0;
     returnAST  = null;
     retTree_   = null;
     inputState.reset();
 }
Example #10
0
 protected internal virtual void  match(AST t, int ttype)
 {
     //System.out.println("match("+ttype+"); cursor is "+t);
     if (t == null || t == ASTNULL || t.Type != ttype)
     {
         throw new MismatchedTokenException(getTokenNames(), t, ttype, false);
     }
 }
Example #11
0
		protected internal virtual void  match(AST t, int ttype)
		{
			//System.out.println("match("+ttype+"); cursor is "+t);
			if (t == null || t == ASTNULL || t.Type != ttype)
			{
				throw new MismatchedTokenException(getTokenNames(), t, ttype, false);
			}
		}
Example #12
0
        /*Is node t equal to this in terms of token type and text? */
        public virtual bool Equals(AST t)
        {
            if (t == null)
            {
                return(false);
            }

            return((Object.Equals(this.getText(), t.getText())) &&
                   (this.Type == t.Type));
        }
Example #13
0
        public void visit(AST node)
        {
            // Flatten this level of the tree if it has no children
            bool flatten = /*true*/ false;
            AST  node2;

            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (node2.getFirstChild() != null)
                {
                    flatten = false;
                    break;
                }
            }

            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (!flatten || node2 == node)
                {
                    tabs();
                }
                if (node2.getText() == null)
                {
                    Console.Out.Write("nil");
                }
                else
                {
                    Console.Out.Write(node2.getText());
                }

                Console.Out.Write(" [" + node2.Type + "] ");

                if (flatten)
                {
                    Console.Out.Write(" ");
                }
                else
                {
                    Console.Out.WriteLine("");
                }

                if (node2.getFirstChild() != null)
                {
                    level++;
                    visit(node2.getFirstChild());
                    level--;
                }
            }

            if (flatten)
            {
                Console.Out.WriteLine("");
            }
        }
Example #14
0
        /// <summary>
        /// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
        /// </summary>
        /// <param name="t">Root of AST Node tree.</param>
        /// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
        public virtual AST dupTree(AST t)
        {
            AST result = dup(t);             // make copy of root

            // copy all children of root.
            if (t != null)
            {
                result.setFirstChild(dupList(t.getFirstChild()));
            }
            return(result);
        }
		public void visit(AST node) 
		{
			// Flatten this level of the tree if it has no children
			bool flatten = /*true*/ false;
			AST node2;
			for (node2 = node; node2 != null; node2 = node2.getNextSibling()) 
			{
				if (node2.getFirstChild() != null) 
				{
					flatten = false;
					break;
				}
			}

			for (node2 = node; node2 != null; node2 = node2.getNextSibling()) 
			{
				if (!flatten || node2 == node) 
				{
					tabs();
				}
				if (node2.getText() == null) 
				{
					Console.Out.Write("nil");
				}
				else 
				{
					Console.Out.Write(node2.getText());
				}

				Console.Out.Write(" [" + node2.Type + "] ");

				if (flatten) 
				{
					Console.Out.Write(" ");
				}
				else 
				{
					Console.Out.WriteLine("");
				}

				if (node2.getFirstChild() != null) 
				{
					level++;
					visit(node2.getFirstChild());
					level--;
				}
			}

			if (flatten) 
			{
				Console.Out.WriteLine("");
			}
		}
Example #16
0
        /// <summary>
        /// Returns a copy of the specified AST Node instance. The copy is obtained by
        /// using the <see cref="ICloneable"/> method Clone().
        /// </summary>
        /// <param name="t">AST Node to copy.</param>
        /// <returns>An AST Node (or null if <c>t</c> is null).</returns>
        public virtual AST dup(AST t)
        {
            // The Java version is implemented using code like this:
            if (t == null)
            {
                return(null);
            }

            AST dup_edNode = createFromAST(t);

            dup_edNode.initialize(t);
            return(dup_edNode);
        }
Example #17
0
 /// <summary>
 /// Make an AST the root of current AST.
 /// </summary>
 /// <param name="currentAST"></param>
 /// <param name="root"></param>
 public virtual void  makeASTRoot(ref ASTPair currentAST, AST root)
 {
     if (root != null)
     {
         // Add the current root as a child of new root
         root.addChild(currentAST.root);
         // The new current child is the last sibling of the old root
         currentAST.child = currentAST.root;
         currentAST.advanceChildToEnd();
         // Set the new root
         currentAST.root = root;
     }
 }
Example #18
0
        /// <summary>
        /// Duplicate AST Node tree rooted at specified AST node and all of it's siblings.
        /// </summary>
        /// <param name="t">Root of AST Node tree.</param>
        /// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
        public virtual AST dupList(AST t)
        {
            AST result = dupTree(t);             // if t == null, then result==null
            AST nt     = result;

            while (t != null)
            {
                // for each sibling of the root
                t = t.getNextSibling();
                nt.setNextSibling(dupTree(t));                 // dup each subtree, building new tree
                nt = nt.getNextSibling();
            }
            return(result);
        }
Example #19
0
        /// <summary>
        /// Creates and initializes a new AST node using the specified AST Node instance.
        /// the new AST node is initialized with the specified Token type ID and string.
        /// The <see cref="System.Type"/> used for creating this new AST node is
        /// determined solely by <c>aNode</c>.
        /// The AST Node type must have a default/parameterless constructor.
        /// </summary>
        /// <param name="aNode">AST Node instance to be used for creating the new AST Node.</param>
        /// <returns>An initialized AST node object.</returns>
        public virtual AST create(AST aNode)
        {
            AST newNode;

            if (aNode == null)
            {
                newNode = null;
            }
            else
            {
                newNode = createFromAST(aNode);
                newNode.initialize(aNode);
            }
            return(newNode);
        }
 // Expected BitSet / not BitSet
 public MismatchedTokenException(string[] tokenNames_, AST node_, BitSet set_, bool matchNot) :
     base("Mismatched Token", "<AST>", -1, -1)
 {
     tokenNames = tokenNames_;
     node       = node_;
     if (node_ == null)
     {
         tokenText = "<empty tree>";
     }
     else
     {
         tokenText = node_.ToString();
     }
     mismatchType = matchNot ? TokenTypeEnum.NotSetType : TokenTypeEnum.SetType;
     bset         = set_;
 }
 // Expected token / not token
 public MismatchedTokenException(string[] tokenNames_, AST node_, int expecting_, bool matchNot) :
     base("Mismatched Token", "<AST>", -1, -1)
 {
     tokenNames = tokenNames_;
     node       = node_;
     if (node_ == null)
     {
         tokenText = "<empty tree>";
     }
     else
     {
         tokenText = node_.ToString();
     }
     mismatchType = matchNot ? TokenTypeEnum.NotTokenType : TokenTypeEnum.TokenType;
     expecting    = expecting_;
 }
		// Expected token / not token
		public MismatchedTokenException(string[] tokenNames_, AST node_, int expecting_, bool matchNot) :
					base("Mismatched Token", "<AST>", - 1, - 1)
		{
			tokenNames = tokenNames_;
			node = node_;
			if (node_ == null)
			{
				tokenText = "<empty tree>";
			}
			else
			{
				tokenText = node_.ToString();
			}
			mismatchType = matchNot ? TokenTypeEnum.NotTokenType : TokenTypeEnum.TokenType;
			expecting = expecting_;
		}
Example #23
0
        /*Walk the tree looking for all exact subtree matches.  Return
         *  an IEnumerator that lets the caller walk the list
         *  of subtree roots found herein.
         */
        public virtual IEnumerator findAll(AST target)
        {
            ArrayList roots = new ArrayList(10);

            //AST sibling;

            // the empty tree cannot result in an enumeration
            if (target == null)
            {
                return(null);
            }

            doWorkForFindAll(roots, target, false);             // find all matches recursively

            return(roots.GetEnumerator());
        }
Example #24
0
        /*Walk the tree looking for all subtrees.  Return
         *  an IEnumerator that lets the caller walk the list
         *  of subtree roots found herein.
         */
        public virtual IEnumerator findAllPartial(AST sub)
        {
            ArrayList roots = new ArrayList(10);

            //AST sibling;

            // the empty tree cannot result in an enumeration
            if (sub == null)
            {
                return(null);
            }

            doWorkForFindAll(roots, sub, true);             // find all matches recursively

            return(roots.GetEnumerator());
        }
Example #25
0
		/*Add a node to the end of the child list for this node */
		public virtual void  addChild(AST node)
		{
			if (node == null)
				return ;
			BaseAST t = this.down;
			if (t != null)
			{
				while (t.right != null)
				{
					t = t.right;
				}
				t.right = (BaseAST) node;
			}
			else
			{
				this.down = (BaseAST) node;
			}
		}
Example #26
0
        private AST createFromNodeTypeObject(Type nodeTypeObject)
        {
            AST newNode = null;

            try
            {
                newNode = (AST)Activator.CreateInstance(nodeTypeObject);
                if (newNode == null)
                {
                    throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeObject.FullName + "'");
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeObject.FullName + "'", ex);
            }
            return(newNode);
        }
Example #27
0
        /// <summary>
        /// Make a tree from a list of nodes.  The first element in the
        /// array is the root.  If the root is null, then the tree is
        /// a simple list not a tree.  Handles null children nodes correctly.
        /// For example, build(a, b, null, c) yields tree (a b c).  build(null,a,b)
        /// yields tree (nil a b).
        /// </summary>
        /// <param name="nodes">List of Nodes.</param>
        /// <returns>AST Node tree.</returns>
        public virtual AST make(params AST[] nodes)
        {
            if (nodes == null || nodes.Length == 0)
            {
                return(null);
            }
            AST root = nodes[0];
            AST tail = null;

            if (root != null)
            {
                root.setFirstChild(null);                 // don't leave any old pointers set
            }
            // link in children;
            for (int i = 1; i < nodes.Length; i++)
            {
                if (nodes[i] == null)
                {
                    continue;
                }
                // ignore null nodes
                if (root == null)
                {
                    // Set the root and set it up for a flat list
                    root = (tail = nodes[i]);
                }
                else if (tail == null)
                {
                    root.setFirstChild(nodes[i]);
                    tail = root.getFirstChild();
                }
                else
                {
                    tail.setNextSibling(nodes[i]);
                    tail = tail.getNextSibling();
                }
                // Chase tail to last sibling
                while (tail.getNextSibling() != null)
                {
                    tail = tail.getNextSibling();
                }
            }
            return(root);
        }
Example #28
0
		private void  doWorkForFindAll(ArrayList v, AST target, bool partialMatch)
		{
			AST sibling;
			
			// Start walking sibling lists, looking for matches.
//siblingWalk: 
			 for (sibling = this; sibling != null; sibling = sibling.getNextSibling())
			{
				if ((partialMatch && sibling.EqualsTreePartial(target)) || (!partialMatch && sibling.EqualsTree(target)))
				{
					v.Add(sibling);
				}
				// regardless of match or not, check any children for matches
				if (sibling.getFirstChild() != null)
				{
					((BaseAST) sibling.getFirstChild()).doWorkForFindAll(v, target, partialMatch);
				}
			}
		}
Example #29
0
        private void  doWorkForFindAll(ArrayList v, AST target, bool partialMatch)
        {
            AST sibling;

            // Start walking sibling lists, looking for matches.
//siblingWalk:
            for (sibling = this; sibling != null; sibling = sibling.getNextSibling())
            {
                if ((partialMatch && sibling.EqualsTreePartial(target)) || (!partialMatch && sibling.EqualsTree(target)))
                {
                    v.Add(sibling);
                }
                // regardless of match or not, check any children for matches
                if (sibling.getFirstChild() != null)
                {
                    ((BaseAST)sibling.getFirstChild()).doWorkForFindAll(v, target, partialMatch);
                }
            }
        }
Example #30
0
        private AST createFromNodeName(string nodeTypeName)
        {
            AST newNode = null;

            ASTNodeCreator creator = (ASTNodeCreator)typename2creator_[nodeTypeName];

            if (creator != null)
            {
                newNode = creator.Create();
                if (newNode == null)
                {
                    throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeName + "'");
                }
            }
            else
            {
                newNode = createFromNodeTypeObject(loadNodeTypeObject(nodeTypeName));
            }
            return(newNode);
        }
Example #31
0
        public virtual string ToStringTree()
        {
            AST    t  = this;
            string ts = "";

            if (t.getFirstChild() != null)
            {
                ts += " (";
            }
            ts += " " + this.ToString();
            if (t.getFirstChild() != null)
            {
                ts += ((BaseAST)t.getFirstChild()).ToStringList();
            }
            if (t.getFirstChild() != null)
            {
                ts += " )";
            }
            return(ts);
        }
Example #32
0
        /*Add a node to the end of the child list for this node */
        public virtual void  addChild(AST node)
        {
            if (node == null)
            {
                return;
            }
            BaseAST t = this.down;

            if (t != null)
            {
                while (t.right != null)
                {
                    t = t.right;
                }
                t.right = (BaseAST)node;
            }
            else
            {
                this.down = (BaseAST)node;
            }
        }
Example #33
0
 /*Is tree rooted at 'this' equal to 't'?  The siblings
  *  of 'this' are ignored.
  */
 public virtual bool EqualsTree(AST t)
 {
     // check roots first.
     if (!this.Equals(t))
     {
         return(false);
     }
     // if roots match, do full list match test on children.
     if (this.getFirstChild() != null)
     {
         if (!this.getFirstChild().EqualsList(t.getFirstChild()))
         {
             return(false);
         }
     }
     else if (t.getFirstChild() != null)
     {
         return(false);
     }
     return(true);
 }
Example #34
0
        private AST createFromAST(AST node)
        {
            AST  newNode       = null;
            Type nodeAsTypeObj = node.GetType();

            ASTNodeCreator creator = (ASTNodeCreator)typename2creator_[nodeAsTypeObj.FullName];

            if (creator != null)
            {
                newNode = creator.Create();
                if (newNode == null)
                {
                    throw new ArgumentException("Unable to create AST Node Type: '" + nodeAsTypeObj.FullName + "'");
                }
            }
            else
            {
                newNode = createFromNodeTypeObject(nodeAsTypeObj);
            }
            return(newNode);
        }
Example #35
0
        public virtual void  xmlSerialize(TextWriter outWriter)
        {
            // print out this node and all siblings
            for (AST node = this; node != null; node = node.getNextSibling())
            {
                if (node.getFirstChild() == null)
                {
                    // print guts (class name, attributes)
                    ((BaseAST)node).xmlSerializeNode(outWriter);
                }
                else
                {
                    ((BaseAST)node).xmlSerializeRootOpen(outWriter);

                    // print children
                    ((BaseAST)node.getFirstChild()).xmlSerialize(outWriter);

                    // print end tag
                    ((BaseAST)node).xmlSerializeRootClose(outWriter);
                }
            }
        }
Example #36
0
        /*Is t an exact structural and equals() match of this tree.  The
         *  'this' reference is considered the start of a sibling list.
         */
        public virtual bool EqualsList(AST t)
        {
            AST sibling;

            // the empty tree is not a match of any non-null tree.
            if (t == null)
            {
                return(false);
            }

            // Otherwise, start walking sibling lists.  First mismatch, return false.
            for (sibling = this; sibling != null && t != null; sibling = sibling.getNextSibling(), t = t.getNextSibling())
            {
                // as a quick optimization, check roots first.
                if (!sibling.Equals(t))
                {
                    return(false);
                }
                // if roots match, do full list match test on children.
                if (sibling.getFirstChild() != null)
                {
                    if (!sibling.getFirstChild().EqualsList(t.getFirstChild()))
                    {
                        return(false);
                    }
                }
                else if (t.getFirstChild() != null)
                {
                    return(false);
                }
            }
            if (sibling == null && t == null)
            {
                return(true);
            }
            // one sibling list has more than the other
            return(false);
        }
Example #37
0
		public virtual void  setFirstChild(AST c)
		{
			down = (BaseAST) c;
		}
Example #38
0
		public virtual bool EqualsTree(AST t)
		{
			return false;
		}
Example #39
0
		public virtual bool EqualsListPartial(AST t)
		{
			return false;
		}
Example #40
0
		public virtual IEnumerator findAll(AST tree)
		{
			return null;
		}
Example #41
0
		public virtual bool EqualsTreePartial(AST t)
		{
			return false;
		}
		public AST node; // handles parsing and treeparsing
		
		public NoViableAltException(AST t) : base("NoViableAlt", "<AST>", - 1, - 1)
		{
			node = t;
		}
		// Expected BitSet / not BitSet
		public MismatchedTokenException(string[] tokenNames_, AST node_, BitSet set_, bool matchNot) :
					base("Mismatched Token", "<AST>", - 1, - 1)
		{
			tokenNames = tokenNames_;
			node = node_;
			if (node_ == null)
			{
				tokenText = "<empty tree>";
			}
			else
			{
				tokenText = node_.ToString();
			}
			mismatchType = matchNot ? TokenTypeEnum.NotSetType : TokenTypeEnum.SetType;
			bset = set_;
		}
Example #44
0
		public abstract void  initialize(AST t);
Example #45
0
		public virtual void  setFirstChild(AST c)
		{
			;
		}
Example #46
0
		/// <summary>
		/// Creates and initializes a new AST node using the specified AST Node instance.
		/// the new AST node is initialized with the specified Token type ID and string.
		/// The <see cref="System.Type"/> used for creating this new AST node is 
		/// determined solely by <c>aNode</c>.
		/// The AST Node type must have a default/parameterless constructor.
		/// </summary>
		/// <param name="aNode">AST Node instance to be used for creating the new AST Node.</param>
		/// <returns>An initialized AST node object.</returns>
		public virtual AST create(AST aNode)
		{
			AST	newNode;

			if (aNode == null)
				newNode = null;
			else
			{			
				newNode = createFromAST(aNode);
				newNode.initialize(aNode);
			}
			return newNode;
		}
Example #47
0
		public virtual void  setNextSibling(AST n)
		{
			right = (BaseAST) n;
		}
Example #48
0
		/// <summary>
		/// Returns a copy of the specified AST Node instance. The copy is obtained by
		/// using the <see cref="ICloneable"/> method Clone().
		/// </summary>
		/// <param name="t">AST Node to copy.</param>
		/// <returns>An AST Node (or null if <c>t</c> is null).</returns>
		public virtual AST dup(AST t)
		{
			// The Java version is implemented using code like this:
			if (t == null)
				return null;

			AST dup_edNode = createFromAST(t);
			dup_edNode.initialize(t);
			return dup_edNode;
		}
Example #49
0
		public virtual void  traceOut(string rname, AST t)
		{
			traceIndent();
			Console.Out.WriteLine("< " + rname + "(" + ((t != null) ? t.ToString() : "null") + ")" + ((inputState.guessing > 0) ? " [guessing]" : ""));
			traceDepth--;
		}
Example #50
0
		/// <summary>
		/// Make an AST the root of current AST.
		/// </summary>
		/// <param name="currentAST"></param>
		/// <param name="root"></param>
		public virtual void  makeASTRoot(ref ASTPair currentAST, AST root)
		{
			if (root != null)
			{
				// Add the current root as a child of new root
				root.addChild(currentAST.root);
				// The new current child is the last sibling of the old root
				currentAST.child = currentAST.root;
				currentAST.advanceChildToEnd();
				// Set the new root
				currentAST.root = root;
			}
		}
Example #51
0
		public virtual bool EqualsList(AST t)
		{
			return false;
		}
Example #52
0
		public virtual void  initialize(AST t)
		{
		}
Example #53
0
		public virtual void  addChild(AST c) {}
Example #54
0
		public virtual IEnumerator findAllPartial(AST subtree)
		{
			return null;
		}
Example #55
0
		/// <summary>
		/// Duplicate AST Node tree rooted at specified AST node and all of it's siblings.
		/// </summary>
		/// <param name="t">Root of AST Node tree.</param>
		/// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
		public virtual AST dupList(AST t)
		{
			AST result = dupTree(t); // if t == null, then result==null
			AST nt = result;
			while (t != null)
			{
				// for each sibling of the root
				t = t.getNextSibling();
				nt.setNextSibling(dupTree(t)); // dup each subtree, building new tree
				nt = nt.getNextSibling();
			}
			return result;
		}
Example #56
0
		private AST createFromAST(AST node)
		{
			AST		newNode			= null;
			Type	nodeAsTypeObj	= node.GetType();

			ASTNodeCreator creator = (ASTNodeCreator) typename2creator_[nodeAsTypeObj.FullName];
			if (creator != null)
			{
				newNode = creator.Create();
				if (newNode == null)
				{
					throw new ArgumentException("Unable to create AST Node Type: '" + nodeAsTypeObj.FullName + "'");
				}
			}
			else
			{
				newNode = createFromNodeTypeObject(nodeAsTypeObj);
			}
			return newNode;
		}
Example #57
0
		public virtual void  setNextSibling(AST n)
		{
			;
		}
Example #58
0
		/// <summary>
		/// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
		/// </summary>
		/// <param name="t">Root of AST Node tree.</param>
		/// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
		public virtual AST dupTree(AST t)
		{
			AST result = dup(t); // make copy of root
			// copy all children of root.
			if (t != null)
			{
				result.setFirstChild(dupList(t.getFirstChild()));
			}
			return result;
		}
Example #59
0
		/*Make sure current lookahead symbol matches the given set
		* Throw an exception upon mismatch, which is catch by either the
		* error handler or by the syntactic predicate.
		*/
		public virtual void  match(AST t, BitSet b)
		{
			if (t == null || t == ASTNULL || !b.member(t.Type))
			{
				throw new MismatchedTokenException(getTokenNames(), t, b, false);
			}
		}
Example #60
0
		/// <summary>
		/// Add a child to the current AST
		/// </summary>
		/// <param name="currentAST">The AST to add a child to</param>
		/// <param name="child">The child AST to be added</param>
		public virtual void  addASTChild(ref ASTPair currentAST, AST child)
		{
			if (child != null)
			{
				if (currentAST.root == null)
				{
					// Make new child the current root
					currentAST.root = child;
				}
				else
				{
					if (currentAST.child == null)
					{
						// Add new child to current root
						currentAST.root.setFirstChild(child);
					}
					else
					{
						currentAST.child.setNextSibling(child);
					}
				}
				// Make new child the current child
				currentAST.child = child;
				currentAST.advanceChildToEnd();
			}
		}