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.action;
22  
23  import org.millscript.millscript.vm.Machine;
24  
25  /**
26   * This class implements the action for an <code>and</code> expression.
27   *
28   * @see org.millscript.millscript.expr.AndExpr
29   * @see org.millscript.millscript.syntax.AndSyntax
30   */
31  public final class AndAction extends Action {
32  
33      /**
34       * The action for the left hand side of the <code>and</code> expression.
35       */
36      private Action lhs;
37  
38      /**
39       * The action for the right hand side of the <code>and</code> expression.
40       */
41      private Action rhs;
42  
43      /**
44       * Constructs a new <code>and</code> action, with the specified actions for
45       * the left and right hand side.
46       *
47       * @param a the action for the left hand side of the expression
48       * @param b the action for the right hand side of the expression
49       */
50      public AndAction( final Action a, final Action b ) {
51          this.lhs = a;
52          this.rhs = b;
53      }
54  
55      /**
56       * @see org.millscript.millscript.action.Action#action(org.millscript.millscript.vm.Machine)
57       */
58      @Override
59      public void action( final Machine mc ) {
60          // Perform the left hand side action and get it's result. For this
61          // action the left hand side must result in a boolean value.
62          if ( lhs.predAct( mc ) ) {
63              // The left hand side action was true, so we execute the right hand
64              // side action
65              rhs.act( mc );
66          } else {
67              // The left hand side was false, so we don't execute the right hand
68              // side at all, we simply return false...
69              mc.pushObject( Boolean.FALSE );
70          }
71      }
72  }