DelGraph() public static method

public static DelGraph ( Node p ) : bool
p Node
return bool
Example #1
0
        void NumberNodes(Node p, State state)
        {
            /* Assigns a state n.state to every node n. There will be a transition from
             * n.state to n.next.state triggered by n.val. All nodes in an alternative
             * chain are represented by the same state.
             */
            if (p == null)
            {
                return;
            }
            if (p.state != null)
            {
                return;                      // already visited;
            }
            if (state == null)
            {
                state = NewState();
            }
            p.state = state;
            if (tab.DelGraph(p))
            {
                state.endOf = curSy;
            }
            switch (p.typ)
            {
            case Node.clas:
            case Node.chr: {
                NumberNodes(p.next, null);
                break;
            }

            case Node.opt: {
                NumberNodes(p.next, null); NumberNodes(p.sub, state);
                break;
            }

            case Node.iter: {
                NumberNodes(p.next, state); NumberNodes(p.sub, state);
                break;
            }

            case Node.alt: {
                NumberNodes(p.sub, state); NumberNodes(p.down, state);
                break;
            }
            }
        }
Example #2
0
 public void ConvertToStates(Node p, Symbol sym)
 {
     curSy = sym;
     if (Tab.DelGraph(p))
     {
         parser.SemErr("token might be empty");
     }
     NumberNodes(p, firstState, true);
     FindTrans(p, true, new BitArray(tab.nodes.Count));
     if (p.typ == Node.iter)
     {
         Step(firstState, p, new BitArray(tab.nodes.Count));
     }
 }
Example #3
0
        // Assigns a state n.state to every node n. There will be a transition from
        // n.state to n.next.state triggered by n.val. All nodes in an alternative
        // chain are represented by the same state.
        // Numbering scheme:
        //  - any node after a chr, clas, opt, or alt, must get a new number
        //  - if a nested structure starts with an iteration the iter node must get a new number
        //  - if an iteration follows an iteration, it must get a new number
        void NumberNodes(Node p, State state, bool renumIter)
        {
            if (p == null)
            {
                return;
            }
            if (p.state != null)
            {
                return;                      // already visited;
            }
            if (state == null || (p.typ == Node.iter && renumIter))
            {
                state = NewState();
            }
            p.state = state;
            if (Tab.DelGraph(p))
            {
                state.endOf = curSy;
            }
            switch (p.typ)
            {
            case Node.clas:
            case Node.chr: {
                NumberNodes(p.next, null, false);
                break;
            }

            case Node.opt: {
                NumberNodes(p.next, null, false);
                NumberNodes(p.sub, state, true);
                break;
            }

            case Node.iter: {
                NumberNodes(p.next, state, true);
                NumberNodes(p.sub, state, true);
                break;
            }

            case Node.alt: {
                NumberNodes(p.next, null, false);
                NumberNodes(p.sub, state, true);
                NumberNodes(p.down, state, renumIter);
                break;
            }
            }
        }