コード例 #1
0
 private bool 过程首部()
 {
     if (Comiler.Peek().LexicalLabel == LexicalLabel.PL0_ProcedureSym)
     {
         Comiler.Read();
         if (Comiler.Peek().LexicalLabel == LexicalLabel.PL0_ID)
         {
             string proce = Comiler.Read().GetString();
             if (!Procedure.Contains(proce))
             {
                 SignTree = SignTree.AddItem(proce);
                 Procedure.AddItem(proce, SignTree);
             }
             else
             {
                 ThrowException("重复的段:" + proce, true);
             }
         }
         else
         {
             ThrowException("标识符");
         }
         if (Comiler.Peek().LexicalLabel == LexicalLabel.PL0_Semicolon)
         {
             Comiler.Read();
         }
         else
         {
             ThrowException("';'");
         }
         return(true);
     }
     return(false);
 }
コード例 #2
0
 public SyntaxAnalysisUnit(StreamWriter writer, IComiler comiler)
 {
     Writer    = writer;
     Comiler   = comiler;
     SignTree  = new SignTree("Global", null, "0");
     Procedure = new ProcedureTable(SignTree);
 }
コード例 #3
0
        public static void GetPath(SignTree running, SignTree target, out string[] callback, out string[] callin)
        {
            Stack <string> stackr = new Stack <string>();
            Stack <string> stackt = new Stack <string>();

            ReadPath(running, stackr);
            ReadPath(target, stackt);
            string[] runs  = stackr.ToArray();
            string[] tars  = stackt.ToArray();
            int      index = 0;

            for (int i = 0; i < runs.Length && i < tars.Length; i++)
            {
                if (runs[i] == tars[i])
                {
                    index = i;
                }
                else
                {
                    break;
                }
            }
            callback = new string[runs.Length - index];
            for (int i = 0; i < callback.Length; i++)
            {
                callback[i] = runs[i + index];
            }
            callin = new string[tars.Length - index];
            for (int i = 0; i < callin.Length; i++)
            {
                callin[i] = tars[i + index];
            }
        }
コード例 #4
0
        public SignTree GetItem(string[] name)
        {
            SignTree item = null;

            if (null != name)
            {
                if (0 < name.Length)
                {
                    for (int i = 0; i < Children.Count; i++)
                    {
                        if (Children[i].Name == name[0])
                        {
                            string[] temp = new string[name.Length - 1];
                            for (int j = 0; j < temp.Length; j++)
                            {
                                temp[j] = name[j + 1];
                            }
                            return(Children[i].GetItem(temp));
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < Children.Count; i++)
                    {
                        if (Children[i].Name == name[0])
                        {
                            return(Children[i]);
                        }
                    }
                }
            }

            return(item);
        }
コード例 #5
0
 public ProcedureTable(SignTree tree)
 {
     Items = new Dictionary <string, SignTree>()
     {
         { tree.Name, tree }
     };
 }
コード例 #6
0
        public SignTree AddItem(string name)
        {
            int      add  = VarTable[VarTable.Count - 1].Value + 4;
            SignTree item = new SignTree(name, this, "[" + InitiationAddress + "+" + add.ToString() + "]");

            Children.Add(item);
            return(item);
        }
コード例 #7
0
        private static void ReadPath(SignTree tree, Stack <string> stack)
        {
            SignTree temp = tree;

            while (null != temp)
            {
                stack.Push(temp.Name);
                temp = temp.Father;
            }
        }
コード例 #8
0
 public SignTree(string name, SignTree father, string init_addr)
 {
     Name              = name;
     Father            = father;
     InitiationAddress = init_addr;
     IfIdentifier      = -1;
     WhileIdentifier   = -1;
     Children          = new List <SignTree>();
     VarTable          = new List <KeyValuePair <string, int> >();
     ConstTable        = new List <KeyValuePair <string, uint> >();
 }
コード例 #9
0
 private void 过程说明部分()
 {
     while (过程首部())
     {
         分程序();
         if (Comiler.Peek().LexicalLabel == LexicalLabel.PL0_Semicolon)
         {
             Comiler.Read();
         }
         else
         {
             ThrowException("';'");
         }
         WriteToFile("ret");
         SignTree = SignTree.Father;
     }
 }
コード例 #10
0
 public void AddItem(string name, SignTree tree)
 {
     Items.Add(name, tree);
 }