0
|
1 package nabble.naml.namespaces;
|
|
2
|
|
3 import nabble.naml.compiler.Command;
|
|
4 import nabble.naml.compiler.CommandSpec;
|
|
5 import nabble.naml.compiler.IPrintWriter;
|
|
6 import nabble.naml.compiler.Interpreter;
|
|
7 import nabble.naml.compiler.Namespace;
|
|
8 import nabble.naml.compiler.Primitive;
|
|
9
|
|
10
|
|
11 @Namespace (
|
|
12 name = "integer",
|
|
13 global = false,
|
|
14 transparent = true
|
|
15 )
|
|
16 public final class IntegerNamespace implements Primitive {
|
|
17 private int i;
|
|
18
|
|
19 public IntegerNamespace(int i) {
|
|
20 this.i = i;
|
|
21 }
|
|
22
|
|
23 public String toString() {
|
|
24 return Integer.toString(i);
|
|
25 }
|
|
26
|
|
27 private static final CommandSpec I = new CommandSpec.Builder()
|
|
28 .dotParameter("i")
|
|
29 .build()
|
|
30 ;
|
|
31
|
|
32 public static final CommandSpec plus = I;
|
|
33
|
|
34 @Command public void plus(IPrintWriter out,Interpreter interp) {
|
|
35 out.print( i = i + interp.getArgAsInt("i") );
|
|
36 }
|
|
37
|
|
38 @Command public void value(IPrintWriter out,Interpreter interp) {
|
|
39 out.print(i);
|
|
40 }
|
|
41
|
|
42 public static final CommandSpec minus = I;
|
|
43
|
|
44 @Command public void minus(IPrintWriter out,Interpreter interp) {
|
|
45 out.print( i = i - interp.getArgAsInt("i") );
|
|
46 }
|
|
47
|
|
48 public static final CommandSpec is_greater_than = I;
|
|
49
|
|
50 @Command public void is_greater_than(IPrintWriter out,Interpreter interp) {
|
|
51 out.print( i > interp.getArgAsInt("i") );
|
|
52 }
|
|
53
|
|
54 public static final CommandSpec is_greater_than_or_equal_to = I;
|
|
55
|
|
56 @Command public void is_greater_than_or_equal_to(IPrintWriter out,Interpreter interp) {
|
|
57 out.print( i >= interp.getArgAsInt("i") );
|
|
58 }
|
|
59
|
|
60 public static final CommandSpec is_less_than = I;
|
|
61
|
|
62 @Command public void is_less_than(IPrintWriter out,Interpreter interp) {
|
|
63 out.print( i < interp.getArgAsInt("i") );
|
|
64 }
|
|
65
|
|
66 public static final CommandSpec is_less_than_or_equal_to = I;
|
|
67
|
|
68 @Command public void is_less_than_or_equal_to(IPrintWriter out,Interpreter interp) {
|
|
69 out.print( i <= interp.getArgAsInt("i") );
|
|
70 }
|
|
71
|
|
72 @Command public void one(IPrintWriter out,Interpreter interp) {
|
|
73 out.print( 1 );
|
|
74 }
|
|
75
|
|
76 }
|