Exemplo n.º 1
0
        public static void new_arr()
        {
            SAR exp  = SAS.Pop();
            SAR type = SAS.Pop();

            if (exp.dataType != "int")
            {
                SemanticArrError(type, exp);
            }
            if (type.value == "null")
            {
                SemanticArrError(type, exp);
            }
            string[] data1 = { "returnType:int", "accessMod:private" };
            Symbol   size  = new Symbol("t", "t" + uniqueCounter++, "t" + type.value, "tvar", data1);

            SymbolTable.Add(size);
            string[] data = { "returnType:" + "@" + type.value, "accessMod:private" };
            Symbol   temp = new Symbol("t", "t" + uniqueCounter++, "t" + type.value, "tvar", data);

            SymbolTable.Add(temp);
            type.symid = temp.symid;
            int classSize = SymbolTable.GetValue(type.symid).size;

            string[] sizeData    = { "returnType:int", "accessMod:public" };
            Symbol   sizeLiteral = new Symbol("g", "N4", "4", "ilit", sizeData);

            SymbolTable.Add(sizeLiteral);
            ICode.MUL(sizeLiteral.symid, exp.symid, size.symid);
            ICode.NEW(size.symid, type.symid);
            type.dataType = "@" + type.value;
            SAS.Push(type);
        }
Exemplo n.º 2
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());
        }