예제 #1
0
        public static void MathOperator()
        {
            bool valid = false;
            SAR  y     = SAS.Pop();
            SAR  x     = SAS.Pop();
            SAR  z     = new SAR(SAR.SARtype.Identifier, x.token, x.value, x.scope);

            z.dataType = x.dataType;
            string op = OS.Peek();

            if (x.dataType[0] == '@' && x.argList != null && x.argList.Count != 0)
            {
                if (x.dataType.Substring(1, x.dataType.Length - 1) == y.dataType)
                {
                    valid = true;
                }
            }
            if (y.dataType[0] == '@' && y.argList != null && y.argList.Count != 0)
            {
                if (y.dataType.Substring(1, y.dataType.Length - 1) == x.dataType)
                {
                    valid = true;
                }
            }
            if (((x.dataType == y.dataType) && (x.dataType == "int")) || valid)
            {
                z.symid  = "t" + uniqueCounter++;
                z.value += "_" + y.value;
                z.scope  = "t";
                string[] data = { "returnType:" + z.dataType, "accessMod:private" };
                Symbol   temp = new Symbol("t", z.symid, z.value, "tvar", data);
                SymbolTable.Add(temp);
                if (op == "+")
                {
                    ICode.ADD(x.symid, y.symid, z.symid);
                }
                else if (op == "-")
                {
                    ICode.SUB(x.symid, y.symid, z.symid);
                }
                else if (op == "*")
                {
                    ICode.MUL(x.symid, y.symid, z.symid);
                }
                else if (op == "/")
                {
                    ICode.DIV(y.symid, x.symid, z.symid);
                }
                SAS.Push(z);
                OS.Pop();
                OSprecidence.Pop();
                return;
            }
            SemanticOperationError(x, y, OS.Peek());
        }