Example #1
0
 private int S(string sentence, AnalysisLog log, int point, TableItem action)
 {
     log.Action = "S" + action.Detail;
     log.GoTo   = "";
     CharStack.Push(sentence[point++]);
     StatusStack.Push(action.Detail);
     return(point);
 }
Example #2
0
 public void add(TableIndex i, TableItem a)
 {
     if (dic.ContainsKey(i))
     {
         if (dic[i].Equals(a)) return;
         else throw new Exception("写入分析表冲突,该文法不是LR(1)文法");
     }
     else
     {
         dic.Add(i, a);
     }
 }
Example #3
0
        private void R(AnalysisLog log, TableItem action)
        {
            log.Action = "R" + action.Detail;
            Production production = CFG._ProductionsMap[action.Detail];
            char       emptyChar  = System.Configuration.ConfigurationManager.AppSettings["Empty"][0];
            int        num        = production.Right == emptyChar.ToString() ? 0 : production.Right.Length;

            for (int i = 0; i < num; i++)
            {
                CharStack.Pop();
                StatusStack.Pop();
            }
            CharStack.Push(production.Left);
            action = Table.GetAction(new TableIndex(StatusStack.Peek(), production.Left));
            StatusStack.Push(action.Detail);
            log.GoTo = action.Detail.ToString();
        }
Example #4
0
 public void add(TableIndex i, TableItem a)
 {
     if (dic.ContainsKey(i))
     {
         if (dic[i].Equals(a))
         {
             return;
         }
         else
         {
             throw new Exception("写入分析表冲突,该文法不是LR(1)文法");
         }
     }
     else
     {
         dic.Add(i, a);
     }
 }
Example #5
0
 private int S(string sentence, AnalysisLog log, int point, TableItem action)
 {
     log.Action = "S" + action.Detail;
     log.GoTo = "";
     CharStack.Push(sentence[point++]);
     StatusStack.Push(action.Detail);
     return point;
 }
Example #6
0
 private void R(AnalysisLog log, TableItem action)
 {
     log.Action = "R" + action.Detail;
     Production production = CFG._ProductionsMap[action.Detail];
     char emptyChar = System.Configuration.ConfigurationManager.AppSettings["Empty"][0];
     int num = production.Right == emptyChar.ToString() ? 0 : production.Right.Length;
     for (int i = 0; i < num; i++)
     {
         CharStack.Pop();
         StatusStack.Pop();
     }
     CharStack.Push(production.Left);
     action = Table.GetAction(new TableIndex(StatusStack.Peek(), production.Left));
     StatusStack.Push(action.Detail);
     log.GoTo = action.Detail.ToString();
 }