Beispiel #1
0
        /// <summary>
        /// Do a step-first walk, building up a buffer of tokens until
        /// you've reached a particular step and print out any rule subroots
        /// insteads of descending.
        /// </summary>
        /// <param name="buf">derivation buffer</param>
        /// <param name="step">derivation steps</param>
        /// <returns></returns>
        protected internal override int getLeftmostDerivation(StringBuilder buf, int step)
        {
            int numReplacements = 0;

            if (step <= 0)
            {
                buf.Append(' ');
                buf.Append(ToString());
                return(numReplacements);
            }
            AST child = getFirstChild();

            numReplacements = 1;
            // walk child printing them out, descending into at most one
            while (child != null)
            {
                if ((numReplacements >= step) || (child is ParseTreeToken))
                {
                    buf.Append(' ');
                    buf.Append(child.ToString());
                }
                else
                {
                    // descend for at least one more derivation; update count
                    int remainingReplacements = step - numReplacements;
                    int n = ((ParseTree)child).getLeftmostDerivation(buf, remainingReplacements);
                    numReplacements += n;
                }
                child = child.getNextSibling();
            }
            return(numReplacements);
        }
Beispiel #2
0
 // 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_;
 }
Beispiel #3
0
 // 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 range / not range
 public MismatchedTokenException(string[] tokenNames_, AST node_, int lower, int upper_, 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.NotRangeType : TokenTypeEnum.RangeType;
     expecting = lower;
     upper = upper_;
 }
 // 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_;
 }
Beispiel #6
0
		public virtual void  traceOut(string rname, AST t)
		{
			traceIndent();
			Console.Out.WriteLine("< " + rname + "(" + ((t != null) ? t.ToString() : "null") + ")" + ((inputState.guessing > 0) ? " [guessing]" : ""));
			traceDepth--;
		}
Beispiel #7
0
 public ASTTreeNode(AST a)
 {
     ASTNode_  = a;
     this.Text = a.ToString();
     this.Nodes.Add("Loading.....");
 }
Beispiel #8
0
		public ASTTreeNode(AST a)
		{
			ASTNode_ = a;
			this.Text = a.ToString();
			this.Nodes.Add("Loading.....");
		}
Beispiel #9
0
 public virtual void  traceOut(string rname, AST t)
 {
     traceIndent();
     Console.Out.WriteLine("< " + rname + "(" + ((t != null) ? t.ToString() : "null") + ")" + ((inputState.guessing > 0) ? " [guessing]" : ""));
     traceDepth--;
 }