コード例 #1
0
        private ThreeAddressValueType GenVariable(LogicExprNode expr)
        {
            if (expr is BooleanNode)
            {
                return(new ThreeAddressLogicValue((expr as BooleanNode).Val));
            }
            if (expr is LogicIdNode)
            {
                return(new ThreeAddressStringValue((expr as LogicIdNode).Name.Name));
            }

            if (expr is LogicOpNode)
            {
                LogicOpNode           op   = expr as LogicOpNode;
                string                res  = GenTempVariable();
                ThreeAddressValueType arg1 = GenVariable(op.Left);
                ThreeAddressValueType arg2 = GenVariable(op.Right);
                ThreeOperator         p    = ThreeCode.ParseOperator(op.Operation);
                AddCode(new ThreeCode(res, p, arg1, arg2));
                return(new ThreeAddressStringValue(res));
            }

            if (expr is LogicNotNode)
            {
                LogicNotNode          lnot = expr as LogicNotNode;
                string                res  = GenTempVariable();
                ThreeAddressValueType arg1 = GenVariable(lnot.LogExpr);
                AddCode(new ThreeCode(res, ThreeOperator.Logic_not, arg1));
                return(new ThreeAddressStringValue(res));
            }

            throw new Exception("UNKNOW VALUE. Send autors of ThreeAddressCode");
        }
コード例 #2
0
        private ThreeAddressValueType GenVariable(ExprNode expr)
        {
            if (expr is IdNode)
            {
                return(new ThreeAddressStringValue((expr as IdNode).Name));
            }

            if (expr is DoubleNumNode)
            {
                return(new ThreeAddressDoubleValue((expr as DoubleNumNode).Num));
            }
            if (expr is IntNumNode)
            {
                return(new ThreeAddressIntValue((expr as IntNumNode).Num));
            }

            if (expr is BinOpNode)
            {
                BinOpNode             op   = expr as BinOpNode;
                string                res  = GenTempVariable();
                ThreeAddressValueType arg1 = GenVariable(op.Left);
                ThreeAddressValueType arg2 = GenVariable(op.Right);
                ThreeOperator         p    = ThreeCode.ParseOperator(op.Op);
                AddCode(new ThreeCode(res, p, arg1, arg2));
                return(new ThreeAddressStringValue(res));
            }

            throw new Exception("UNKNOW VALUE. Send autors of ThreeAddressCode");
        }
コード例 #3
0
 public override void VisitAssignNode(AssignNode a)
 {
     if (a.Expr is BinOpNode binOp && (binOp.Left is IdNode || binOp.Left is DoubleNumNode || binOp.Left is IntNumNode) &&
         (binOp.Right is IdNode || binOp.Right is DoubleNumNode || binOp.Right is IntNumNode))
     {
         ThreeAddressValueType arg1 = GenVariable(binOp.Left);
         ThreeAddressValueType arg2 = GenVariable(binOp.Right);
         AddCode(new ThreeCode(a.Id.ToString(), ThreeCode.ParseOperator(binOp.Op), arg1, arg2));
     }