예제 #1
0
 public For(Assign init, Expression comparison, Assign update, Statement stmt, LineId line)
     : base(line)
 {
     this.init = init;
     this.comparison = comparison;
     this.stmt = stmt;
     this.update = update;
 }
예제 #2
0
        private Statement ForStatement()
        {
            LineId line = lexer.LineId; // This is the line that the FOR key word is used on
            Match(Token.For);

            Location location = Location(); // this is the counting variable

            Match(Token.Equals);

            Expression startVal = Expression(); // This is the starting value

            Match(Token.To);

            Expression endVal = Expression(); // this is the ending value

            Match(Token.EndOfLine);

            Block block = Block(Token.Next);

            LineId endLine = lexer.LineId;  // This is the line that the NEXT keyword is used on
            Match(Token.Next);
            Match(Token.Variable);

            Assign init = new Assign(location, startVal, line);
            Assign update = new Assign(location, new Add(new LocationReference(location, endLine),
                new NumberLiteral(1, endLine), endLine), endLine);
            Expression comparison = RelationalExpression.CompareLessThanEquals(new LocationReference(location, line), endVal, line);
            return new For(init, comparison, update, block, line);
        }