Ejemplo n.º 1
0
        static void Term(out int type)
        {
            int   type2;
            int   op;
            Label shortcircuit = new Label(!known);

            Factor(out type);
            while (StartOf(14))
            {
                MulOp(out op);
                if (op == CodeGen.and)
                {
                    CodeGen.BooleanOp(shortcircuit, CodeGen.and);
                }
                Factor(out type2);
                switch (op)
                {
                case CodeGen.and:
                    if (!IsBool(type) || !IsBool(type2))
                    {
                        SemError("boolean operands needed");
                    }
                    type = Types.boolType;
                    break;

                default:
                    if (!IsArith(type) || !IsArith(type2))
                    {
                        SemError("arithmetic operands needed");
                        type = Types.noType;
                    }
                    CodeGen.BinaryOp(op);
                    break;
                }
            }
            shortcircuit.Here();
        }
Ejemplo n.º 2
0
        static void AddExp(out int type)
        {
            int   type2;
            int   op;
            Label shortcircuit = new Label(!known);

            type = Types.noType;
            if (la.kind == plus_Sym)
            {
                Get();
                Term(out type);
                if (!IsArith(type))
                {
                    SemError("arithmetic operand needed");
                }
            }
            else if (la.kind == minus_Sym)
            {
                Get();
                Term(out type);
                if (!IsArith(type))
                {
                    SemError("arithmetic operand needed");
                }
                CodeGen.NegateInteger();
            }
            else if (StartOf(13))
            {
                Term(out type);
            }
            else
            {
                SynErr(55);
            }
            while (la.kind == plus_Sym || la.kind == minus_Sym || la.kind == barbar_Sym)
            {
                AddOp(out op);
                if (op == CodeGen.or)
                {
                    CodeGen.BooleanOp(shortcircuit, CodeGen.or);
                }
                Term(out type2);
                switch (op)
                {
                case CodeGen.or:
                    if (!IsBool(type) || !IsBool(type2))
                    {
                        SemError("boolean operands needed");
                    }
                    type = Types.boolType;
                    break;

                default:
                    if (!IsArith(type) || !IsArith(type2))
                    {
                        SemError("arithmetic operands needed");
                        type = Types.noType;
                    }
                    CodeGen.BinaryOp(op);
                    break;
                }
            }
            shortcircuit.Here();
        }