Exemplo n.º 1
0
 public State(ParsHead head)
 {
     count=0;
     parsHead=head;
     first=new StateNode(0);
     first.laws.add(0,0);
     this.stateTravers(first);
 }
Exemplo n.º 2
0
 public StateNode(int number)
 {
     this.laws    = new StateLaws();
     this.exports = new StateExports();
     next=null;
     this.stateNum = number;
 }
Exemplo n.º 3
0
 private void stateTravers(StateNode tra)
 {
     StateLawNode lawNode=tra.laws.Head;
     Stack lawExists=new Stack();
     while(lawNode!=null)
     {
         LawsNode law=parsHead.findLaw(lawNode.data.lawNum);
         if(law!=null)
         {
             PartsNode part=law.parts[lawNode.data.dotPos];
             if(part!=null)
             {
                 if(!part.item.isTerminal )
                 {
                     if(!lawExists.Contains(part.item.name))
                     {
                         Stack lawNumbers = new Stack();
                         lawNumbers.Clear();
                         law.parts.Parent.Parent.NonTerminals.findLaws(part.item.name,lawNumbers);
                         while(lawNumbers.Count != 0)
                             tra.laws.add(0,(int)lawNumbers.Pop());
                         lawExists.Push(part.item.name);
                     }
                 }
             }
         }
         lawNode=lawNode.next;
     }
 }
Exemplo n.º 4
0
 private void makeStats(int stateNumber)
 {
     StateNode newStateNode;
     Stack exports=new Stack();
     StateNode temp = this.first;
     while(temp!=null)
     {
         if(temp.StateNumber == stateNumber)
         {
             StateLawNode stateLaw = temp.laws.Head;
             while(stateLaw!=null)
             {
                 LawsNode law = this.parsHead.findLaw(stateLaw.data.lawNum);
                 PartsNode part = law.parts[stateLaw.data.dotPos];
                 if(part != null)
                 {
                     if(!exports.Contains(part.item.name))
                     {
                         exports.Push(part.item.name);
                         newStateNode=new StateNode(this.count+1);
                         newStateNode.laws.add(stateLaw.data.dotPos+1,stateLaw.data.lawNum);
                         StateLawNode remainLaw = stateLaw.next;
                         while(remainLaw!=null)
                         {
                             LawsNode remLaw = this.parsHead.findLaw(remainLaw.data.lawNum);
                             PartsNode remPart = remLaw.parts[remainLaw.data.dotPos];
                             if(remPart != null)//if2
                             {
                                 if(remPart.item.name==part.item.name)
                                 {
                                     newStateNode.laws.add(remainLaw.data.dotPos+1,remainLaw.data.lawNum);
                                 }
                             }//if2
                             remainLaw = remainLaw.next;
                         }//while
                         this.stateTravers(newStateNode);
                         StateNode existState;
                         existState=this.isCreated(newStateNode);
                         if(existState==null)
                         {
                             this.add(newStateNode);
                             temp.exports.add(part.item.name,part.item.isTerminal,newStateNode.StateNumber);
                             this.makeStats(newStateNode.StateNumber);
                         }
                         else
                         {
                             temp.exports.add(part.item.name,part.item.isTerminal,existState.StateNumber);
                         }
                     }//if new export
                 }//if dot place is not end
                 else
                 {
                     stateLaw.data.IsDotEnded = true;
                 }
                 stateLaw = stateLaw.next;
             }
         }//if find state
         temp = temp.next;
     }//while in state
 }
Exemplo n.º 5
0
        private StateNode isCreated(StateNode newNode)
        {
            bool foundMatchLaw=false;
            StateNode node=first;
              //.......... for all states search for new state
            while(node!=null)
            {
                //.............check count of laws of two state
                if(node.laws.LawCount!=newNode.laws.LawCount)
                {
                    node = node.next;
                    continue;
                }

                StateLawNode temp=node.laws.Head;
                //........for any laws in this state search for a law in new state
                while(temp!=null)
                {
                    StateLawNode newData=newNode.laws.Head;
                    foundMatchLaw=false;//is found any mached law in new state
                    while(newData!=null)
                    {
                        if(temp.data.lawNum==newData.data.lawNum)
                            if(temp.data.dotPos==newData.data.dotPos)
                            {
                                foundMatchLaw=true;
                                break;
                            }
                        newData=newData.next;
                    }
                    if(!foundMatchLaw)
                        break;
                    //....do search for other laws
                    temp=temp.next;
                }
                if(foundMatchLaw)
                {
                    return node;
                }
                node=node.next;
            }
            return null;
        }
Exemplo n.º 6
0
 private StateNode add(StateNode newNode)
 {
     StateNode temp = first;
     count++;
     if(first == null)
     {
         first = newNode;
         return first;
     }
     while(temp.next!=null)
         temp=temp.next;
     temp.next =newNode;
     return temp.next;
 }