示例#1
0
		// ISCNode members
		public void Evaluate(Scope scope)
		{
			// Predefined functinos
			if (Function.Name == "putchar")
			{
				foreach (IExprNode expr in Parameters)
				{
					expr.Evaluate(scope);
					Console.WriteLine(expr.IntValue);
				}
				return;
			}

			Scope globalScope = scope.GlobalScope;


            if (FuncDeclsContainer.Contains(Function))
				throw new InterpreterException("Call to undefined function: " + Function.Name);

			Scope childScope = new Scope(globalScope);
            FuncDefNode funcDef = globalScope.FuncDefs.Get(Function);
			for (int i = 0; i < Parameters.Count; ++i)
			{
				Parameters[i].Evaluate(scope);
				childScope.Add(funcDef.Parameters[i].Name, new IntVariable(Parameters[i].IntValue));
			}
			funcDef.Body.Evaluate(childScope);
		}
示例#2
0
 // ISCNode members
 public void Evaluate(Scope scope)
 {
     Debug.Assert(Left != null && Right != null, "Null operand in binary expression");
     Left.Evaluate(scope);
     Right.Evaluate(scope);
     switch (Type)
     {
         case BinaryExpressionType.ADD:
             intValue_ = Left.IntValue + Right.IntValue;
             break;
         case BinaryExpressionType.SUB:
             intValue_ = Left.IntValue - Right.IntValue;
             break;
         case BinaryExpressionType.MUL:
             intValue_ = Left.IntValue * Right.IntValue;
             break;
         case BinaryExpressionType.DIV:
             intValue_ = Left.IntValue / Right.IntValue;
             break;
         case BinaryExpressionType.MOD:
             intValue_ = Left.IntValue % Right.IntValue;
             break;
         case BinaryExpressionType.ASSIGN:
             IdentNode identNode = Left as IdentNode;
             if (identNode == null)
                 throw new InterpreterException("Left operand of '=' must be an lvalue");
             if (!scope.IsDefined(identNode.Name))
                 throw new InterpreterException("Undefined variable: " + identNode.Name);
             intValue_ = Right.IntValue;
             scope.Get(identNode.Name).Value = intValue_;
             break;
         default:
             throw new InterpreterException("Unexpected expression type");
     }
 }
        // ISCNode members
        public void Evaluate(Scope scope)
        {
            foreach (ISCNode statement in Statements)
            {
                if (statement is CompoundStatementNode)
                {
                    Scope childScope = new Scope(scope);
                    statement.Evaluate(childScope);
                }
                else if (statement is IExprNode)
                {
                    statement.Evaluate(scope);
                }
                else if (statement is VarDefNode)
                {
                    scope.Add(statement as VarDefNode);
                }
            }

            // TODO: Evaluate compound statement
        }
示例#4
0
 // ISCNode members
 public void Evaluate(Scope parentScope)
 {
     // Nothing to do here
 }
示例#5
0
 public void Evaluate(Scope parentScope)
 {
     // Really nothing to do here
 }
示例#6
0
 public void Run()
 {
     Scope scope = new Scope(globalScope_);
     mainFuncDef_.Body.Evaluate(scope);
 }
示例#7
0
 // ISCNode members
 public void Evaluate(Scope parentScope)
 {
 }
示例#8
0
		// ISCNode members
		public void Evaluate(Scope scope)
		{
			if (!scope.IsDefined(Name))
				throw new InterpreterException("Undefined variable: " + Name);
			intValue_ = scope.Get(Name).Value;
		}
示例#9
0
 public Scope(Scope parent = null)
 {
     Parent = parent;
 }
示例#10
0
 // ISCNode members
 public void Evaluate(Scope parentScope)
 {
     // TODO: evaluate root node
 }