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.BindingListAction;
24  import org.millscript.millscript.vm.CompilerState;
25  
26  import java.util.Stack;
27  
28  /**
29   * This class represents a for loop list binding expression. A list binding
30   * expression binds successive items from a list to a name.
31   */
32  public final class BindingListExpr extends BindingExpr< BindingListAction > {
33  
34      /**
35       * The expression that generates the list of items to bind elements from.
36       */
37      private final Expr< ? > inExpr;
38  
39      /**
40       * The name expression to bind successive list items to.
41       */
42      private final NameExpr name;
43  
44      /**
45       * Constructs a new list binding expression, with the supplied name and list
46       * expressions.
47       *
48       * @param   a   the name expression to bind to
49       * @param   b   the list expression to bind elements from
50       */
51      public BindingListExpr( final NameExpr a, final Expr< ? > b ) {
52          name = a;
53          inExpr = CheckExpr.make( b );
54      }
55  
56      /**
57       * @see org.millscript.millscript.expr.Expr#compileIt()
58       */
59      @Override
60      public BindingListAction compileIt() {
61          return new BindingListAction( name.getIdent(), inExpr.compile() );
62      }
63  
64      /**
65       * @see org.millscript.millscript.expr.BindingExpr#pushNames(java.util.Stack)
66       */
67      @Override
68      void pushNames( final Stack< Expr > s ) {
69          s.push( name );
70      }
71  
72      /**
73       * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
74       */
75      @Override
76      public void resolve( final CompilerState state ) {
77          this.inExpr.resolve( state );
78      }
79  
80      /**
81       * @see org.millscript.millscript.expr.Expr#showComponents(int)
82       */
83      @Override
84      void showComponents( final int n ) {
85          this.inExpr.show( n );
86      }
87  
88  }