Пример #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);
		}
        // 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
        }