public Empty Visit(DekiScriptGeneratorVar expr, DekiScriptGeneratorEvaluationState state)
        {
            // store previous state of variable
            var previousVar = state.State.Env.Vars[expr.Var];

            try {
                // initialize the variable
                state.State.Env.Vars.Add(expr.Var, Eval(expr.Expression, state));

                // generate values
                EvalNext(expr, state);
            } finally {
                // restore the variable
                state.State.Env.Vars.Add(expr.Var, previousVar);
            }
            return(Empty.Value);
        }
 public Empty Visit(DekiScriptGeneratorVar expr, DekiScriptGeneratorEvaluationState state)
 {
     state.Env.Locals.Add(expr.Var, expr.Expression.VisitWith(DekiScriptExpressionEvaluation.Instance, state.Env));
     Generate(expr, state);
     return(Empty.Value);
 }
Beispiel #3
0
	void GeneratorNext(out DekiScriptGenerator gen) {
		Location location = Location.None;
		Location wherelocation = Location.None;
		DekiScriptExpression where = null; 
		List<string> names = new List<string>(); 
		DekiScriptExpression expr = null; 
		bool assign = false;
		string value = null;
		gen = null;
		
		if (la.kind == 19) {
			Get();
			location = t.Location; 
			Expect(1);
			names.Add(t.val); 
			if (la.kind == 31) {
				Get();
				Expect(1);
				value = t.val; 
				Expect(52);
				Expression(out expr);
				if (la.kind == 70) {
					Get();
					wherelocation = t.Location; 
					Expression(out where);
				}
			} else if (la.kind == 20 || la.kind == 52) {
				while (la.kind == 20) {
					Get();
					Expect(1);
					names.Add(t.val); 
				}
				Expect(52);
				Expression(out expr);
				if (la.kind == 70) {
					Get();
					wherelocation = t.Location; 
					Expression(out where);
				}
			} else if (la.kind == 12) {
				Get();
				Expression(out expr);
				assign = true; 
			} else SynErr(92);
		} else if (la.kind == 21) {
			Get();
			location = t.Location; 
			Expression(out expr);
		} else SynErr(93);
		if (la.kind == 20) {
			Get();
			GeneratorNext(out gen);
		}
		if(where != null) gen = new DekiScriptGeneratorIf(wherelocation, where, gen);
		if(names.Count == 0) gen = new DekiScriptGeneratorIf(location, expr, gen);
		else if(assign) gen = new DekiScriptGeneratorVar(location, names[0], expr, gen);
		else if(value == null) gen = new DekiScriptGeneratorForeachValue(location, names.ToArray(), expr, gen);
		else gen = new DekiScriptGeneratorForeachKeyValue(location, names[0], value, expr, gen);
		
	}