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>&&</code> expression.
27 *
28 * @see org.millscript.millscript.expr.AndAbsentExpr
29 * @see org.millscript.millscript.syntax.AndAbsentSyntax
30 */
31 public final class AndAbsentAction extends Action {
32
33 /**
34 * The action for the left hand side of the <code>&&</code>
35 * expression.
36 */
37 private Action lhs;
38
39 /**
40 * The action for the right hand side of the <code>&&</code>
41 * expression.
42 */
43 private Action rhs;
44
45 /**
46 * Constructs a new <code>&&</code> action, with the specified
47 * actions for the left and right hand side.
48 *
49 * @param a the action for the left hand side of the expression
50 * @param b the action for the right hand side of the expression
51 */
52 public AndAbsentAction( final Action a, final Action b ) {
53 this.lhs = a;
54 this.rhs = b;
55 }
56
57 /**
58 * @see org.millscript.millscript.action.Action#action(org.millscript.millscript.vm.Machine)
59 */
60 @Override
61 public void action( final Machine mc ) {
62 // The left hand side results in a single value, so perform it's action
63 // and get it.
64 Object left = lhs.act1( mc );
65 if ( left != null ) {
66 // The left hand side was not null, so we ignore it and just
67 // perform the right hand side action
68 rhs.act( mc );
69 } else {
70 // The left hand side was null, so this action returns null
71 mc.pushObject( null );
72 }
73 }
74 }