Beispiel #1
0
        public void SetType(int id, SimpleScriptTypes type)
        {
            if (!symbolTable.ContainsKey(id))
            {
                throw new ArgumentException("Undeclared identifier.");
            }
            SymbolTableElement x = symbolTable[id];

            switch (type)
            {
            case SimpleScriptTypes.Integer:
                SymbolTableIntegerElement stie = new SymbolTableIntegerElement(x.Name, 0);
                symbolTable[id] = stie;
                break;

            case  SimpleScriptTypes.Double:
                SymbolTableDoubleElement stde = new SymbolTableDoubleElement(x.Name, 0.0);
                symbolTable[id] = stde;
                break;

            case SimpleScriptTypes.Boolean:
                SymbolTableBoolElement stbe = new SymbolTableBoolElement(x.Name, false);
                symbolTable[id] = stbe;
                break;

            case SimpleScriptTypes.String:
                SymbolTableStringElement stse = new SymbolTableStringElement(x.Name, "");
                symbolTable[id] = stse;
                break;
            }
        }
Beispiel #2
0
        public void Execute()
        {
            SymbolTableElement st = SymbolTable.GetInstance.Get(symbolId);

            if (st is SymbolTableIntegerElement)
            {
                int value = Convert.ToInt32(Console.ReadLine());
                SymbolTableIntegerElement ist = st as SymbolTableIntegerElement;
                ist.Value = value;
                return;
            }
            if (st is SymbolTableBoolElement)
            {
                bool value = Convert.ToBoolean(Console.ReadLine());
                SymbolTableBoolElement bst = st as SymbolTableBoolElement;
                bst.Value = value;
                return;
            }
            if (st is SymbolTableDoubleElement)
            {
                double value = Convert.ToDouble(Console.ReadLine());
                SymbolTableDoubleElement dst = st as SymbolTableDoubleElement;
                dst.Value = value;
                return;
            }
            if (st is SymbolTableStringElement)
            {
                string value = Console.ReadLine();
                SymbolTableStringElement sst = st as SymbolTableStringElement;
                sst.Value = value;
                return;
            }
        }
        public void Execute()
        {
            SymbolTableElement elem = SymbolTable.GetInstance.Get(id);

            if (elem is SymbolTableIntegerElement)
            {
                SymbolTableIntegerElement ielem = (SymbolTableIntegerElement)elem;
                if (exp.Type == SimpleScriptTypes.Integer)
                {
                    ielem.Value = (long)exp.Evaluate();
                }
                else
                {
                    throw new InvalidOperationException("Invalide assignment.");
                }
                return;
            }
            if (elem is SymbolTableBoolElement)
            {
                SymbolTableBoolElement belem = (SymbolTableBoolElement)elem;
                if (exp.Type == SimpleScriptTypes.Boolean)
                {
                    belem.Value = (bool)exp.Evaluate();
                }
                else
                {
                    throw new InvalidOperationException("Invalide assignment.");
                }
                return;
            }
            if (elem is SymbolTableDoubleElement)
            {
                SymbolTableDoubleElement delem = (SymbolTableDoubleElement)elem;
                if (exp.Type == SimpleScriptTypes.Double || exp.Type == SimpleScriptTypes.Integer)
                {
                    delem.Value = (double)exp.Evaluate();
                }
                else
                {
                    throw new InvalidOperationException("Invalide assignment.");
                }
            }
            if (elem is SymbolTableStringElement)
            {
                SymbolTableStringElement selem = (SymbolTableStringElement)elem;
                if (exp.Type == SimpleScriptTypes.Double)
                {
                    selem.Value = exp.Evaluate().ToString();
                }
                else
                {
                    throw new InvalidOperationException("Invalide assignment.");
                }
            }
        }