Beispiel #1
0
		public void PreParseExpression(ParseContext context)
		{
			//var pl = context.Current;
			Condition.PreParseExpression(context);
			context.AddLevel();

			foreach (var line in CodeLines)
			{
				line.PreParseExpression(context);
			}

			context.RemoveLevel();
		}
Beispiel #2
0
		public string ToString(ParseContext context)
		{
			var result = "while(" + Condition.ToString(context) + ")\n";
			result += context.Pad + "{\n";
			context.AddLevel();

			foreach (var line in CodeLines)
			{
				var createVariable = line as CreateVariable;
				if (createVariable != null)
				{
					createVariable.DefaultInitialize(context);
				}
				result += context.Pad + line.ToString(context) + ";\n";
			}

			context.RemoveLevel();
			result += context.Pad + "}";
			return result;
		}
Beispiel #3
0
		public Expression ToExpression(ParseContext context)
		{
			var conditionExpression = Condition.ToExpression(context);
			context.AddLevel();

			var thenLine = new List<Expression>();
			var listOfThenVars = new List<ParameterExpression>();
			foreach (var line in ThenCodeLines)
			{
				var expLine = line.ToExpression(context);

				var createVariable = line as CreateVariable;
				if (createVariable != null)
				{
					listOfThenVars.Add((ParameterExpression)expLine);
					expLine = createVariable.DefaultInitialize(context);
				}
				thenLine.Add(expLine);
			}
			var thenBlock = Expression.Block(listOfThenVars.ToArray(), thenLine);

			context.RemoveLevel();

			var elseLine = new List<Expression>();
			if (ElseCodeLines.Count > 0)
			{
				context.AddLevel();
				var listOfElseVars = new List<ParameterExpression>();
				foreach (var line in ElseCodeLines)
				{
					var expLine = line.ToExpression(context);

					var createVariable = line as CreateVariable;
					if (createVariable != null)
					{
						listOfElseVars.Add((ParameterExpression)expLine);
						expLine = createVariable.DefaultInitialize(context);
					}
					elseLine.Add(expLine);
				}

				context.RemoveLevel();
				var elseBlock = Expression.Block(listOfElseVars, elseLine);
				return Expression.IfThenElse(conditionExpression, thenBlock, elseBlock);
			}
			return Expression.IfThen(conditionExpression, thenBlock);
		}
Beispiel #4
0
		public Expression ToExpression(ParseContext context)
		{
			var conditionExpression = Condition.ToExpression(context);
			context.AddLevel();

			var thenLine = new List<Expression>();
			var listOfThenVars = new List<ParameterExpression>();
			foreach (var line in CodeLines)
			{
				var expLine = line.ToExpression(context);

				var createVariable = line as CreateVariable;
				if (createVariable != null)
				{
					listOfThenVars.Add((ParameterExpression)expLine);
					expLine = createVariable.DefaultInitialize(context);
				}
				thenLine.Add(expLine);
			}
			var thenBlock = Expression.Block(listOfThenVars.ToArray(), thenLine);

			context.RemoveLevel();

			LabelTarget label = Expression.Label(Guid.NewGuid().ToString());
			var ifThenElse = Expression.IfThenElse(
																conditionExpression,
																thenBlock,
																Expression.Break(label));
			return Expression.Loop(ifThenElse, label);
		}