View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2001-2004 Open World Ltd
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.millscript.expr;
22  
23  import org.millscript.millscript.action.ForConditionWhileAction;
24  import org.millscript.millscript.vm.CompilerState;
25  
26  /**
27   * This class represents a for loop while condition expression. A while
28   * condition loops while the expression is true, then executes the termination
29   * expression and terminates the loop.
30   */
31  public final class ForConditionWhileExpr extends ForConditionExpr< ForConditionWhileAction > {
32  
33      /**
34       * The while expression. While this condition is true, this iterator allows
35       * the for loop to continue. When this condition is false, this iterator
36       * will cause the for loop to terminate.
37       */
38      private final Expr< ? > whileExpr;
39  
40      /**
41       * The termination expression. This expression will be executed when this
42       * condition causes the for loop to terminate.
43       */
44      private final Expr< ? > terminateExpr;
45  
46      /**
47       * Constructs a new while condition expression, with the supplied while and
48       * terminate expressions.
49       *
50       * @param   e   the while condition expression
51       * @param   t   the while condition termination expression
52       */
53      public ForConditionWhileExpr( final Expr< ? > e, final Expr< ? > t ) {
54          // The while condition expression must return one result
55          whileExpr = CheckExpr.make( e );
56          terminateExpr = t;
57      }
58  
59      /**
60       * @see org.millscript.millscript.expr.Expr#compileIt()
61       */
62      @Override
63      public ForConditionWhileAction compileIt() {
64          return new ForConditionWhileAction( whileExpr.compile(), terminateExpr.compile() );
65      }
66  
67      /**
68       * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
69       */
70      @Override
71      public void resolve( final CompilerState state ) {
72          this.whileExpr.resolve( state );
73          this.terminateExpr.resolve( state );
74      }
75  
76      /**
77       * @see org.millscript.millscript.expr.Expr#showComponents(int)
78       */
79      @Override
80      void showComponents( final int n ) {
81          this.whileExpr.show( n );
82          this.terminateExpr.show( n );
83      }
84  
85  }