private ForLoop ResolveWithRange(Expression[] rangeArgs) { List<Executable> init = new List<Executable>(); Expression increment = new IntegerConstant(null, 1); if (rangeArgs.Length == 3) { if (rangeArgs[2] is IntegerConstant || rangeArgs[2] is Variable) { increment = rangeArgs[2]; } string variableName = "crayon_conversion_step_" + VARIABLE_ALLOCATION_COUNTER++; init.Add(new Assignment(new Variable(null, variableName), new Token("=", null, 0, 0, TokenType.OTHER), rangeArgs[2])); increment = new Variable(null, variableName); } Expression start = new IntegerConstant(null, 0); // if 2 or 3 are present, then an explicit start is given if (rangeArgs.Length > 1) { start = rangeArgs[0]; } Expression end = null; if (rangeArgs.Length == 1) { end = rangeArgs[0]; } else { end = rangeArgs[1]; } if (end is IntegerConstant || end is Variable) { // this is fine } else { string variableName = "crayon_conversion_length_" + VARIABLE_ALLOCATION_COUNTER++; init.Add(new Assignment(new Variable(null, variableName), new Token("=", null, 0, 0, TokenType.OTHER), end)); end = new Variable(null, variableName); } init.Add(new Assignment(new Variable(this.IteratorVariable, this.IteratorVariable.Value), new Token("=", null, 0, 0, TokenType.OTHER), start)); Expression condition = new BinaryOpChain( new Expression[] { new Variable(this.IteratorVariable, this.IteratorVariable.Value), end }, new Token[] { new Token("<", null, 0, 0, TokenType.OTHER) }); List<Executable> step = new List<Executable>() { new Assignment( new Variable(this.IteratorVariable, this.IteratorVariable.Value), new Token("+=", null, 0, 0, TokenType.OTHER), increment) }; return new ForLoop(this.FirstToken, this, init, condition, step, this.Body); }
private void SerializeVariable(List<string> output, Variable variable) { if (variable.Value == "self") { output.Add("this"); } else { output.Add(variable.Value); } }
private void SerializeVariable(List<string> output, Variable variable) { output.Add(variable.Value); }