示例#1
0
        //****************************************************************************************************
		public void Step(Subroutine.Moment pos, int forpos) {
			Namespace cn = InterprEnvironment.Instance.CurrentNamespace;
			VarBase res = cn[m_counter_var];
			if (!res.IsInt())
				throw new CalcException("“ип переменной - счетчика цикла был изменен");
			int resval = (res as IntVar).Val;
			resval++;
			res = new IntVar(resval);
			cn[m_counter_var] = res;
			if (resval > m_end_res.Val)
				pos.GoTo(m_next_pos + 1);
			else
				pos.GoTo(forpos + 1);
		}
示例#2
0
        //****************************************************************************************************
		public void Execute(Subroutine.Moment pos) {
			VarBase resb, rese;
			resb = m_begin.Calculate();
			if (!resb.IsInt())
				throw new CalcException("√раницы изменени¤ счетчика должны быть целыми");
			IntVar resbi = resb as IntVar;
			Namespace cn = InterprEnvironment.Instance.CurrentNamespace;
			cn[m_counter_var] = resb;
			rese = m_end.Calculate();
			if (!rese.IsInt())
				throw new CalcException("√раницы изменени¤ счетчика должны быть целыми");
			m_end_res = rese as IntVar;
			if (resbi.Val > m_end_res.Val)
				pos.GoTo(m_next_pos + 1);
			else
				pos.Next();
		}
示例#3
0
        //****************************************************************************************************
		public VarBase Perform(ArgList al) {
			Namespace ns = new Namespace(InterprEnvironment.Instance.CurrentNamespace);
			ns["result"] = new IntVar(0);
			int argc = m_args.Count;
			if (al.Count != argc)
				throw new CalcException("Ќеверное число параметров");
			al.Reset();
			for (int i = 0; i < argc; i++) {
				ns[m_args[i] as System.String] = al.Get();
			}
			InterprEnvironment.Instance.CurrentNamespace = ns;
			Moment moment = new Moment(this);
			if (m_count > 1) {
				try {
					moment.Run();
				}
				catch (SyntaxErrorException ex) {
					throw ex;
				}
				catch (CalcException ex) {
					throw new CalcException("ќшибка в функции " + m_name + "[] в строке " + (moment.Pos + 1) + " : " + ex.Message);
				}
			}
			VarBase res = ns["result"];
			InterprEnvironment.Instance.CurrentNamespace = ns.PreviousNamespace;
			if (res == null)
				throw new CalcException("ќшибка в функции " + m_name + "[] : переменна¤ result не определена на момент выхода");
			return res;
		}