private void FillAction(State tempState, ExtendRule tempER)
 {
     if (tempER.PointRight.Count == 0)
     {
         if (tempER.leftRule == OG.startSymbol)
         {
             ActionNode node = new ActionNode(ActionChoice.accept);
             tempState.myAction.Add("#", node);
             return;
         }
         else
         {
             ActionNode node = new ActionNode(ActionChoice.reduct, tempER.OriginRule);
             foreach (string tmp in OG.tSymbol)
             {
                 tempState.myAction.Add(tmp, node);
             }
             return;
         }
     }
     else
     {
         if (OG.StrToSymbol(tempER.PointRight[0]).kind == symKind.term)
         {
             int next = -1;
             if (tempState.DFAedge.TryGetValue(tempER.PointRight[0], out next))
             {
                 ActionNode node = new ActionNode(ActionChoice.addin, next);
                 tempState.myAction.Add(tempER.PointRight[0], node);
             }
         }
     }
 }
Exemple #2
0
 public void SetRuleSet(ExtendRule er)
 {
     if (!ruleSet.Contains(er))
     {
         ruleSet.Add(er);
     }
 }
 private int CalNextState(ExtendRule nowER)
 {
     if (nowER.PointRight.Count == 0)
     {
         return(-1);
     }
     return(ERSet[nowER.nextRuleNum].BelongState[0]);
 }
 private int FindERinSet(ExtendRule tempER)
 {
     for (int i = 0; i < ERSet.Count; i++)
     {
         if (ERSet[i].leftRule == tempER.leftRule &&
             ERSet[i].PointLeft == tempER.PointLeft &&
             ERSet[i].PointRight == tempER.PointRight)
         {
             return(i);
         }
     }
     return(-1);
 }
 public void CreateERSet()
 {
     for (int i = 0; i < OG.pat.Count; i++)
     {
         Rule tempR = OG.pat[i];
         for (int j = 0; j <= tempR.right.Count; j++)
         {
             ExtendRule er = new ExtendRule(tempR, j);
             er.OriginRule = i;
             if (j < tempR.right.Count)
             {
                 er.nextRuleNum = ERSet.Count + 1;
             }
             else
             {
                 er.nextRuleNum = -1;
             }
             ERSet.Add(er);
         }
     }
 }
        private void SameStateRule(int erNum, List <ExtendRule> stateER)
        {
            ExtendRule er        = ERSet[erNum];
            int        nextIndex = -1;

            stateER.Add(er);
            if (er.PointRight.Count != 0)
            {
                if (OG.StrToSymbol(er.PointRight[0]).kind == symKind.notTerm)
                {
                    do
                    {
                        nextIndex = FindNext(er.PointRight[0], nextIndex + 1);
                        if (nextIndex != -1)
                        {
                            SameStateRule(nextIndex, stateER);
                        }
                    } while (nextIndex != -1);
                }
            }
        }