Ejemplo n.º 1
0
        public void Visit(OrOperator or)
        {
            var trueLabel = MakeNewLabel();
            var endLabel  = MakeNewLabel();

            or.Left.Accept(this);
            var leftOperand = tacs.Last().Result;

            tacs.Add(Tac.IfTrue(leftOperand, trueLabel));
            or.Right.Accept(this);
            var rightOperand = tacs.Last().Result;

            tacs.Add(Tac.IfTrue(rightOperand, trueLabel));
            var resultVariable = MakeNewTemp();

            tacs.Add(Tac.Assign("0", resultVariable));
            tacs.Add(Tac.Goto(endLabel));
            tacs.Add(Tac.Label(trueLabel, resultVariable));
            tacs.Add(Tac.Assign("1", resultVariable));
            tacs.Add(Tac.Label(endLabel, resultVariable));
        }