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 a <code>||</code> expression.
27 *
28 * @see org.millscript.millscript.expr.OrAbsentExpr
29 * @see org.millscript.millscript.syntax.OrAbsentSyntax
30 */
31 public final class OrAbsentAction extends Action {
32
33 /**
34 * The action for the left hand side of the <code>||</code> expression.
35 */
36 private Action lhs;
37
38 /**
39 * The action for the right hand side of the <code>||</code> expression.
40 */
41 private Action rhs;
42
43 /**
44 * Constructs a new <code>||</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 OrAbsentAction( 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 // The left hand side results in a single value, so perform it's action
61 // and get it.
62 Object left = lhs.act1( mc );
63 if ( left != null ) {
64 // The left hand side was not null, so we simply return it
65 mc.pushObject( left );
66 } else {
67 // The left hand side was null, so we perform the right hand action
68 rhs.act( mc );
69 }
70 }
71
72 }