Exemplo n.º 1
0
        public override string go()
        {
            Lexems.Lexema l = getToken();
               string s = "";
               if (l == null) return "";
               if (l.GetType().Name != "UnOperNot")
               {

               this.lexems.Add(l);
               }
               else
               {
               s = "\tnot bx\n";
               }

               while ((l = getToken()) != null)
               {
               this.lexems.Add(l);
               }
               SubExpression e=new SubExpression(this);

               string result=e.go();
               calculations = e.calculations;
               string tmp = s;
               if(result !=null)
               {
               s = result ;
               }

            s += "\tmov bx,"+e.result+"\n"+tmp+"\n";
            this.result = "bx";

               return s;
        }
Exemplo n.º 2
0
        public override string go()
        {
            Lexems.Lexema l=null;
            this.result = "ax";
            string s=null;

            while ((l = getToken()) != null && (this.command = isBinaryOperand(l)) == null)
            {
                if (l.GetType().Name == "Begin")
                {

                        this.lexems.Add(l);

                        while ((l = getToken()) != null)
                        {
                            this.lexems.Add(l);
                        }

                    Operand o = new Operand(this);
                    string operand = o.go();
                    this.result = operand;
                    this.calculations = o.calculations;
                    return "\n";

                }
                this.lexems.Add(l);
            }
            if (l == null)
            {

                Operand o =new Operand(this);
                string operand = o.go();
                calculations = o.calculations;
                if (operand != null)
                {

                }
                else
                {
                    addError(new BinaryOperatorOperandMissed(), 0);
                }
                return "\tmov ax," + operand+"\n";
            }
            SubExpression eL = new SubExpression(this);
            string lOperand = eL.go();

            while ((l = getToken()) != null )
            {
                this.lexems.Add(l);
            }

            SubExpression eR = new SubExpression(this);
            string rOperand = eR.go();

            if (lOperand == null||rOperand==null)
            {
                addError(new BinaryOperatorOperandMissed(), 0);
            }
            else
            {
                this.result="ax";
                s = lOperand + "\n";
                s += "\tmov ax," + eL.result+"\n";
                s += rOperand + "\n";
                s += "\t" + command + " ax," + eR.result+"\n";

            }
            return s;
        }