Пример #1
0
 public ParseTreeVisitor Alternate()
 {
     if (currentNode == null)
     {
         return(null);
     }
     currentNode = currentNode.next;
     return(currentNode != null ? this : null);
 }
Пример #2
0
 public ParseTreeVisitor(ParseTreeVisitor otherVisitor)
 {
     Forest      = otherVisitor.Forest;
     i           = otherVisitor.i;
     j           = otherVisitor.j;
     currentNode = otherVisitor.currentNode;
     parentNode  = otherVisitor.parentNode;
     currentType = otherVisitor.currentType;
 }
Пример #3
0
 public ParseTreeVisitor Left()
 {
     if (currentNode == null)
     {
         return(null);
     }
     parentNode  = currentNode;
     j           = parentNode.k;
     currentNode = Forest.P[i, j, (int)parentNode.B].list;
     currentType = parentNode.B;
     return(this);
 }
Пример #4
0
        protected void recurse(int i, int j, NonTerminalSymbol nt, int d, Action <NonTerminalSymbol, ParseTreeNodeMatch, int, bool> act)
        {
            ParseTreeNode      thisnode = Forest.P[i, j, (int)nt];
            ParseTreeNodeMatch m        = thisnode.list;

            act(nt, m, i, m == null);
            if (m != null)
            {
                recurse(i, m.k, m.B, d + 1, act);
                recurse(i + m.k + 1, j - m.k - 1, m.C, d + 1, act);
            }
        }
Пример #5
0
 public ParseTreeVisitor Right()
 {
     if (currentNode == null)
     {
         return(null);
     }
     parentNode  = currentNode;
     i           = i + parentNode.k + 1;
     j           = j - parentNode.k - 1;
     currentNode = Forest.P[i, j, (int)parentNode.C].list;
     currentType = parentNode.C;
     return(this);
 }
Пример #6
0
 public ParseTreeVisitor(ParseForest treeCollection, NonTerminalSymbol whichTree)
 {
     if (whichTree == 0)
     {
         throw new Exception("Can't pass 0 to ParseTreeVisitor constructor");
     }
     Forest      = treeCollection;
     i           = 0;
     j           = Forest.n - 1;
     currentNode = Forest.P[i, j, (int)whichTree].list;
     parentNode  = null;
     currentType = whichTree;
 }
Пример #7
0
        protected string WithAlternates(ParseForest forest, ParseTreeVisitor resetVisitor, SemanticContext context, string retryScope = null)
        {
            string             errors = "";
            ParseTreeNodeMatch c      = resetVisitor.currentNode;

            for (; errors != null && c != null; c = c.next)
            {
                try
                {
                    var visitor = new ParseTreeVisitor(resetVisitor)
                    {
                        currentNode = c
                    };
                    visitor.Right();                     // does this need be here? what if we want Left?  Should i pass in these two lines as delegate?
                    CreateSymbol(forest, visitor, context);
                    errors = null;
                }
                catch (Backtrack b)
                {
                    "--BACKTRACK".Log();
                    errors += b.Message + Environment.NewLine;
                    if (retryScope == null)
                    {
                        continue;
                    }
                    Scope.Abandon();
                    Scope.EnterNew(retryScope);
                }
            }
            if (errors != null && c == null)
            {
                if (retryScope != null)
                {
                    Scope.Abandon();
                }
                return(errors);
            }
            return(null);
        }
Пример #8
0
        public void PrintBackpointerData(ParseForest tree)
        {
            if (!bp)
            {
                return;
            }
            ParseTreeNode[, ,] P = tree.P;
            int n = tree.n, r = tree.r;

            for (int k = n - 1; k >= 0; k--)
            {
                foreach (int i in 1.to(n - k))
                {
                    "\t".LogAnd();
                    string retval = "";
                    foreach (int nonterminals in 1.to(r))
                    {
                        if (P[i, k, nonterminals].match)
                        {
                            int c = 0;
                            for (ParseTreeNodeMatch m = P[i, k, nonterminals].list; m != null; m = m.next)
                            {
                                c++;
                            }
                            retval += (retval == "" ? "" : ",") + c;
                        }
                    }
                    retval.LogAnd();
                }
                "".Log();
            }
            // final line: words
            foreach (int i in 1.to(n))
            {
                ("\t" + tree.a[i]).LogAnd();
            }
            "".Log();
        }
Пример #9
0
        protected void Recurse(int i, int j, NonTerminalSymbol nt, int d, visitor act)
        {
            ParseTreeNode thisnode = P[i, j, (int)nt];

            if (!thisnode.match)
            {
                return;
            }
            ParseTreeNodeMatch m = thisnode.list;

            if (m != null)
            {
                for (; m != null; m = m.next)
                {
                    act(this, d, false, nt, m.B, m.C, i, j);
                    Recurse(i, m.k, m.B, d + 1, act);
                    Recurse(i + m.k + 1, j - m.k - 1, m.C, d + 1, act);
                }
            }
            else
            {
                act(this, d, true, nt, 0, 0, i, j);
            }
        }
Пример #10
0
 public ParseTreeNode(bool m)
 {
     match = m; list = null;
 }
Пример #11
0
 public ParseTreeNodeMatch(int partition, NonTerminalSymbol b, NonTerminalSymbol c, ParseTreeNodeMatch item)
 {
     k = partition; B = b; C = c; next = item;
 }
Пример #12
0
 public ParseTreeNode(bool m, int k, NonTerminalSymbol B, NonTerminalSymbol C, ParseTreeNodeMatch prev)
 {
     match = m; list = new ParseTreeNodeMatch(k, B, C, prev);
 }