Пример #1
0
 public Compiler(string path)
 {
     source = path;
     la     = new lexical_analysis(this);
     sa     = new syntax_Analysis(this);
     st     = new symbol_table(this);
     error  = new Error(this);
     pc     = new Pcode();
 }
Пример #2
0
        //添加到符号表中
        public void add(symlist sym)
        {
            syntax_Analysis sa = compiler.sa;

            if (sa.level > point)
            {
                point++;
                dx[point] = dx[point - 1];
            }
            else if (sa.level < point)
            {
                //int delnum = dx[point] - dx[point - 1];
                //for (int i = 0; i < delnum; i++)
                //    stable.RemoveAt(stable.Count - 1);
                //point--;
            }
            dx[point]++;
            record re = new record();

            re.name = compiler.la.word;
            if (sym == symlist.constsym)
            {
                re.kind = "constant";
                re.val  = compiler.la.num;
                stable.Add(re);
            }
            else if (sym == symlist.varsym)
            {
                re.kind  = "variable";
                re.level = sa.level;
                //获取地址还没写re.adr =
                re.adr = compiler.sa.getadd();
                stable.Add(re);
            }
            else if (sym == symlist.proceduresym)
            {
                re.kind  = "procedure";
                re.level = sa.level;
                stable.Add(re);
            }
        }