Пример #1
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();
        }