예제 #1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public PL0Compiler(string path)
 {
     try
     {
         source = new FileStream(path, FileMode.Open);
         SA     = new SymbolAnalysis(this);
         ST     = new SymbolTable(this);
         EH     = new ErrorHandle(this);
         GSA    = new GrammarAndSemanticAna(this);
         PCG    = new PCodeGenetate();
     }
     catch (IOException e)
     {
         Console.WriteLine(e.Message);
         source = null;
         SA     = null;
         ST     = null;
         EH     = null;
         GSA    = null;
         PCG    = null;
     }
     finally
     {
     }
 }
예제 #2
0
        /// <summary>
        /// 字符表登录函数
        /// </summary>
        /// <param name="K">类型</param>
        public void Enter(ObjectK K)
        {
            GrammarAndSemanticAna GS = compiler.GSA;

            if (GS.getLevel() > lev)
            {
                lev++;
                tx[lev] = tx[lev - 1];
            }
            else if (GS.getLevel() < lev)
            {
                lev--;
            }

            tx[lev]++;

            SymTabItem item = new SymTabItem();

            item.kind = K;
            item.name = compiler.SA.tname;
            switch (K)
            {
            case ObjectK.constant:
                item.value = compiler.SA.tnumber;
                SymTable.Add(item);
                break;

            case ObjectK.variable:
                item.level   = compiler.GSA.getLevel();
                item.address = compiler.GSA.getAddress();
                SymTable.Add(item);
                break;

            case ObjectK.procedure:
                item.level = compiler.GSA.getLevel();
                SymTable.Add(item);
                break;
            }
        }