Пример #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;
            }
        }
Пример #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;
            }
        }
Пример #3
0
        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.");
                }
            }
        }
Пример #4
0
 public ForStatement(SymbolTableIntegerElement ielem, Expression initExpr, Expression endExpr, StatementList statements)
 {
     this.ielem = ielem;
     //TODO null
     if (initExpr.Type != SimpleScriptTypes.Integer || endExpr.Type != SimpleScriptTypes.Integer)
     {
         throw new ArgumentException();
     }
     this.initExpr   = initExpr;
     this.endExpr    = endExpr;
     this.statements = statements;
 }