Exemplo n.º 1
0
 public void interpretNextMT()
 {
     for (int i = 1; i <= r.getNumProg(); ++i)
     {
         Statement st = r.getPS(i).es.top();
         r.getPS(i).es.pop();
         if (st is AssignStatement)
         {
             AssignStatement _as = (AssignStatement)st;
             r.getPS(i).vt.set(
                 _as.getVar(),
                 _as.getE().eval(r.getPS(i).vt, r.getPS(i).hp));
             r.getPS(i).vt.printTable();
         }
         else if (st is CompoundStatement)
         {
             CompoundStatement cs = (CompoundStatement)st;
             r.getPS(i).es.push(cs.getS2());
             r.getPS(i).es.push(cs.getS1());
         }
         else if (st is IfStatement)
         {
             IfStatement _is = (IfStatement)st;
             if (_is.getE().eval(r.getPS(i).vt, r.getPS(i).hp) != 0)
             {
                 r.getPS(i).es.push(_is.getS1());
             }
             else
             {
                 r.getPS(i).es.push(_is.getS2());
             }
         }
         else if (st is PrintStatement)
         {
             PrintStatement pr = (PrintStatement)st;
             r.getPS(i).ob.add(pr.getE().eval(r.getPS(i).vt, r.getPS(i).hp).ToString());
         }
         else if (st is ForkStatement)
         {
             r.addPs(r.getPS(i).ob, r.getPS(i).vt, ((ForkStatement)st).getS());
         }
         else if (st is WHStatement)
         {
             WHStatement wh   = (WHStatement)st;
             int         addr = r.getPS(i).vt.get(wh.getVN());
             r.getPS(i).hp.mod(addr, wh.getV().eval(r.getPS(i).vt, r.getPS(i).hp));
         }
         if (r.getPS(i).es.isEmpty())
         {
             r.removePs(i);
             --i;
         }
     }
 }
Exemplo n.º 2
0
        public void interpretNext()
        {
            Statement st = r.ps.es.top();

            r.ps.es.pop();
            if (st is AssignStatement)
            {
                AssignStatement _as = (AssignStatement)st;
                r.ps.vt.set(
                    _as.getVar(),
                    _as.getE().eval(r.ps.vt, r.ps.hp));
                r.ps.vt.printTable();
            }
            else if (st is CompoundStatement)
            {
                CompoundStatement cs = (CompoundStatement)st;
                r.ps.es.push(cs.getS2());
                r.ps.es.push(cs.getS1());
            }
            else if (st is IfStatement)
            {
                IfStatement _is = (IfStatement)st;
                if (_is.getE().eval(r.ps.vt, r.ps.hp) != 0)
                {
                    r.ps.es.push(_is.getS1());
                }
                else
                {
                    r.ps.es.push(_is.getS2());
                }
            }
            else if (st is PrintStatement)
            {
                PrintStatement pr = (PrintStatement)st;
                r.ps.ob.add(pr.getE().eval(r.ps.vt, r.ps.hp).ToString());
            }
        }