1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.millscript.expr;
22
23 import org.millscript.millscript.action.BindingFromAction;
24 import org.millscript.millscript.vm.CompilerState;
25
26 import java.util.Stack;
27
28 /**
29 * This class represents a for loop from counter binding expression. A from
30 * counter expression binds a counter to a name, where the counter increases on
31 * each iteration. This condition should never cause the for loop to terminate,
32 * as the counter should continue to infinity.
33 *
34 * @see org.millscript.millscript.syntax.ForSyntax
35 * @see BindingFromAction
36 */
37 public final class BindingFromExpr extends BindingExpr< BindingFromAction > {
38
39 /**
40 * The expression that generates the starting point for the counter.
41 */
42 private final Expr< ? > fromExpr;
43
44 /**
45 * The name expression to bind the counter to.
46 */
47 private final NameExpr name;
48
49 /**
50 * Constructs a new from counter binding expression, with the suplied name
51 * and starting point expression.
52 *
53 * @param n the name expression to bind to
54 * @param f the counter starting point expression
55 */
56 public BindingFromExpr( final NameExpr n, final Expr< ? > f ) {
57 name = n;
58 fromExpr = CheckExpr.make( f );
59 }
60
61 /**
62 * @see org.millscript.millscript.expr.Expr#compileIt()
63 */
64 @Override
65 public BindingFromAction compileIt() {
66 return new BindingFromAction( name.getIdent(), fromExpr.compile() );
67 }
68
69 /**
70 * @see org.millscript.millscript.expr.BindingExpr#pushNames(java.util.Stack)
71 */
72 @Override
73 void pushNames( final Stack< Expr > s ) {
74 s.push( name );
75 }
76
77 /**
78 * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
79 */
80 @Override
81 public void resolve( final CompilerState state ) {
82 this.fromExpr.resolve( state );
83 }
84
85 /**
86 * @see org.millscript.millscript.expr.Expr#showComponents(int)
87 */
88 @Override
89 void showComponents( final int n ) {
90 this.fromExpr.show( n );
91 }
92
93 }