示例#1
0
 public int eval(MapInterface <String, int> tbl, HeapInterface <int> heap)
 {
     if (op.Equals("<"))
     {
         return((e1.eval(tbl, heap) < e2.eval(tbl, heap)) ? 1 : 0);
     }
     if (op.Equals("<="))
     {
         return((e1.eval(tbl, heap) <= e2.eval(tbl, heap)) ? 1 : 0);
     }
     if (op.Equals("=="))
     {
         return((e1.eval(tbl, heap).Equals(e2.eval(tbl, heap))) ? 1 : 0);
     }
     if (op.Equals("!="))
     {
         return((!e1.eval(tbl, heap).Equals(e2.eval(tbl, heap))) ? 1 : 0);
     }
     if (op.Equals(">"))
     {
         return((e1.eval(tbl, heap) > e2.eval(tbl, heap)) ? 1 : 0);
     }
     if (op.Equals(">="))
     {
         return((e1.eval(tbl, heap) >= e2.eval(tbl, heap)) ? 1 : 0);
     }
     return(0);
 }
        public PrgState execute(PrgState state)
        {
            MapInterface <String, int> symTbl = state.SymTable;
            HeapInterface <int>        heap   = state.HeapTable;

            heap.Update(symTbl [Id], Exp.eval(symTbl, heap));
            return(null);
        }
示例#3
0
 public int eval(MapInterface <String, int> tbl, HeapInterface <int> heap)
 {
     if (tbl.ContainsKey(id))
     {
         return(tbl [id]);
     }
     throw new UninitializedVariableException();
 }
示例#4
0
 public int eval(MapInterface<String, int> tbl, HeapInterface<int> heap)
 {
     try {
         return readInteger ("");
     } catch (UnexpectedTypeException) {
         return eval (tbl, heap);
     }
 }
示例#5
0
 public int eval(MapInterface <String, int> tbl, HeapInterface <int> heap)
 {
     try {
         return(readInteger(""));
     } catch (UnexpectedTypeException) {
         return(eval(tbl, heap));
     }
 }
示例#6
0
        public PrgState execute(PrgState state)
        {
            MapInterface <String, int> symTbl = state.SymTable;
            HeapInterface <int>        heap   = state.HeapTable;
            int val = exp.eval(symTbl, heap);

            symTbl [id] = val;
            return(null);
        }
示例#7
0
        public PrgState execute(PrgState state)
        {
            ListInterface <int>        output = state.Output;
            MapInterface <String, int> symTbl = state.SymTable;
            HeapInterface <int>        heap   = state.HeapTable;

            output.Add(Exp.eval(symTbl, heap));
            return(null);
        }
示例#8
0
 //optional field, but good to have
 public PrgState(StackInterface<IStmt> stack, MapInterface<String, int> dictionary, HeapInterface<int> heap, ListInterface<int> list, IStmt prg)
 {
     id = generator++;
     exeStack = stack;
     symTable = dictionary;
     heapTable = heap;
     output = list;
     originalProgram = prg;
     exeStack.Push (originalProgram);
 }
示例#9
0
        //optional field, but good to have

        public PrgState(StackInterface <IStmt> stack, MapInterface <String, int> dictionary, HeapInterface <int> heap, ListInterface <int> list, IStmt prg)
        {
            id              = generator++;
            exeStack        = stack;
            symTable        = dictionary;
            heapTable       = heap;
            output          = list;
            originalProgram = prg;
            exeStack.Push(originalProgram);
        }
 public ProgramState(Stack <Statement.Statement> executionStack,
                     ConcurrentDictionary <string, Value.Value> symbolTable, List <Value.Value> outTable, Statement.Statement st)
 {
     this.executionStack = executionStack;
     this.symbolTable    = symbolTable;
     this.outTable       = outTable;
     this.origProgram    = st;
     this.executionStack.Push(st);
     fileTable = new ConcurrentDictionary <string, FileStream>();
     heapTable = new Heap();
 }
示例#11
0
        public PrgState execute(PrgState state)
        {
            MapInterface <String, int> symTbl = state.SymTable;
            HeapInterface <int>        heap   = state.HeapTable;

            if (Exp.eval(symTbl, heap) != 0)
            {
                state.ExeStack.Push(this);
                state.ExeStack.Push(this.Stmt);
            }
            return(null);
        }
示例#12
0
 public int eval(MapInterface <String, int> tbl, HeapInterface <int> heap)
 {
     if (op.Equals("&&"))
     {
         return((e1.eval(tbl, heap) != 0 && e2.eval(tbl, heap) != 0) ? 1 : 0);
     }
     if (op.Equals("||"))
     {
         return((e1.eval(tbl, heap) != 0 || e2.eval(tbl, heap) != 0) ? 1 : 0);
     }
     return(0);
 }
示例#13
0
 public int eval(MapInterface<String, int> tbl, HeapInterface<int> heap)
 {
     if (op == "+")
         return (e1.eval (tbl, heap) + e2.eval (tbl, heap));
     if (op == "-")
         return (e1.eval (tbl, heap) - e2.eval (tbl, heap));
     if (op == "*")
         return (e1.eval (tbl, heap) * e2.eval (tbl, heap));
     if (op == "/") {
         if (e2.eval (tbl, heap) == 0)
             throw new DivisionByZeroException ();
         return (e1.eval (tbl, heap) / e2.eval (tbl, heap));
     }
     return 0;
 }
 public int eval(MapInterface<String, int> tbl, HeapInterface<int> heap)
 {
     if (op.Equals ("<"))
         return (e1.eval (tbl, heap) < e2.eval (tbl, heap)) ? 1 : 0;
     if (op.Equals ("<="))
         return (e1.eval (tbl, heap) <= e2.eval (tbl, heap)) ? 1 : 0;
     if (op.Equals ("=="))
         return (e1.eval (tbl, heap).Equals (e2.eval (tbl, heap))) ? 1 : 0;
     if (op.Equals ("!="))
         return (!e1.eval (tbl, heap).Equals (e2.eval (tbl, heap))) ? 1 : 0;
     if (op.Equals (">"))
         return (e1.eval (tbl, heap) > e2.eval (tbl, heap)) ? 1 : 0;
     if (op.Equals (">="))
         return (e1.eval (tbl, heap) >= e2.eval (tbl, heap)) ? 1 : 0;
     return 0;
 }
示例#15
0
 public int eval(MapInterface <String, int> tbl, HeapInterface <int> heap)
 {
     if (op == "+")
     {
         return(e1.eval(tbl, heap) + e2.eval(tbl, heap));
     }
     if (op == "-")
     {
         return(e1.eval(tbl, heap) - e2.eval(tbl, heap));
     }
     if (op == "*")
     {
         return(e1.eval(tbl, heap) * e2.eval(tbl, heap));
     }
     if (op == "/")
     {
         if (e2.eval(tbl, heap) == 0)
         {
             throw new DivisionByZeroException();
         }
         return(e1.eval(tbl, heap) / e2.eval(tbl, heap));
     }
     return(0);
 }
示例#16
0
 public int eval(MapInterface<String, int> tbl, HeapInterface<int> heap)
 {
     return number;
 }
示例#17
0
 public int eval(MapInterface <String, int> tbl, HeapInterface <int> heap)
 {
     return(number);
 }
        public Value.Value evaluate(ConcurrentDictionary <string, Value.Value> symTable, HeapInterface heapTable)
        {
            if (!(exp1.evaluate(symTable, heapTable).GetTypeInter().HasSameType(new IntType())) ||
                !(exp2.evaluate(symTable, heapTable).GetTypeInter().HasSameType(new IntType())))
            {
                throw new Exception("Invalid types: Arithmetic Expression Works only with INTS!\n");
            }
            Int32 v1 = ((IntValue)exp1.evaluate(symTable, heapTable)).getValue();
            Int32 v2 = ((IntValue)exp2.evaluate(symTable, heapTable)).getValue();
            Int32 res;

            switch (operation)
            {
            case ("+"): {
                res = v1 + v2;
                break;
            }

            case ("-"): {
                res = v1 - v2;
                break;
            }

            case (":"): {
                if (v2 == 0)
                {
                    throw new Exception("DIVISION BY 0\n");
                }
                res = v1 / v2;
                break;
            }

            case ("*"):
            {
                res = v1 * v2;
                break;
            }

            default:
                throw new Exception("Invalid operation: " + operation);
            }
            return(new IntValue(res));
        }
示例#19
0
 public int eval(MapInterface<String, int> tbl, HeapInterface<int> heap)
 {
     if (tbl.ContainsKey (id))
         return tbl [id];
     throw new UninitializedVariableException ();
 }
示例#20
0
 public int eval(MapInterface <String, int> tbl, HeapInterface <int> heap)
 {
     return(exp.eval(tbl, heap) == 0 ? 1 : 0);
 }
        public Value.Value evaluate(ConcurrentDictionary<string, Value.Value> symTable, HeapInterface heapTable)
        {
            Value.Value result = new BoolValue(false);

            if(!expr1.evaluate(symTable, heapTable).GetTypeInter().HasSameType(new IntType()) ||
               !expr2.evaluate(symTable, heapTable).GetTypeInter().HasSameType(new IntType()) )
                throw new Exception("Incompatible types for expressions!\n");

            Int32 v1 = ((IntValue) expr1.evaluate(symTable, heapTable)).getValue();
            Int32 v2 = ((IntValue) expr2.evaluate(symTable, heapTable)).getValue();
            switch (operation)
            {
                case ("=="):
                {
                    result = new BoolValue(v1==v2);
                    break;

                }
                case (">="):
                {
                    result = new BoolValue(v1>=v2);
                    break;
                }
                case (">"):
                {
                    result = new BoolValue(v1>v2);
                    break;
                }
                case("<="):
                {
                    result = new BoolValue(v1<=v2) ;
                    break;
                }
                case ("<"):
                {
                    result = new BoolValue(v1<v2);
                    break;
                }
                default:
                    throw new Exception("Invalid operator given!");

            }

            return result;
        }
示例#22
0
        public int eval(MapInterface <String, int> tbl, HeapInterface <int> heap)
        {
            int address = tbl [id];

            return(heap.Get(address));
        }
 public Value.Value evaluate(ConcurrentDictionary <string, Value.Value> symTable, HeapInterface heapTable)
 {
     if (!symTable.ContainsKey(id))
     {
         throw new Exception("Invalid variable name!\n");
     }
     return(symTable[id]);
 }
 public Value.Value evaluate(ConcurrentDictionary <string, Value.Value> symTable, HeapInterface heapTable)
 {
     return(val);
 }
示例#25
0
 public int eval(MapInterface<String, int> tbl, HeapInterface<int> heap)
 {
     int address = tbl [id];
     return heap.Get (address);
 }
示例#26
0
 public int eval(MapInterface<String, int> tbl, HeapInterface<int> heap)
 {
     return exp.eval (tbl, heap) == 0 ? 1 : 0;
 }
示例#27
0
        public Value.Value evaluate(ConcurrentDictionary <string, Value.Value> symTable, HeapInterface heapTable)
        {
            if (!(expr1.evaluate(symTable, heapTable).GetTypeInter().HasSameType(new BoolType())) ||
                !(expr2.evaluate(symTable, heapTable).GetTypeInter().HasSameType(new BoolType())))
            {
                throw new Exception("INVALID TYPES FOR LOGIC EXPRESSION!\n");
            }

            Boolean b1 = ((BoolValue)expr1.evaluate(symTable, heapTable)).getValue();
            Boolean b2 = ((BoolValue)expr2.evaluate(symTable, heapTable)).getValue();
            Boolean b3 = false;

            if (operation == "&")
            {
                b3 = b1 & b2;
            }
            else if (operation == "||")
            {
                b3 = b1 || b2;
            }
            else
            {
                throw new Exception("Invalid logic operation!\n");
            }
            return(new BoolValue(b3));
        }
示例#28
0
        public Value.Value evaluate(ConcurrentDictionary <string, Value.Value> symTable, HeapInterface heapTable)
        {
            /*
             * • the expression must be evaluated to a RefValue. If not, the execution is stopped with an
             * appropriate error message.
             * • Take the address component of the RefValue computed before and use it to access Heap
             * table and return the value associated to that address. If the address is not a key in Heap table,
             * the execution is stopped with an appropriate error message.
             */
            if (!(expression.evaluate(symTable, heapTable) is ReferenceValue))
            {
                throw new Exception("Evaluation of expression: " + expression + " should result in a Reference Value!\n");
            }

            Int32 address = ((ReferenceValue)expression.evaluate(symTable, heapTable)).getAddress();

            if (!((Heap)heapTable).ContainsKey(address))
            {
                throw new Exception("Invalid Heap Address!\n");
            }
            return(((Heap)heapTable)[address]);
        }