KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ast > Binary


1 package polyglot.ast;
2
3 import polyglot.util.Enum;
4
5 /**
6  * A <code>Binary</code> represents a Java binary expression, an
7  * immutable pair of expressions combined with an operator.
8  */

9 public interface Binary extends Expr
10 {
11     /** Binary expression operator. */
12     public static class Operator extends Enum JavaDoc {
13     Precedence prec;
14
15         public Operator(String JavaDoc name, Precedence prec) {
16         super(name);
17         this.prec = prec;
18     }
19
20     /** Returns the precedence of the operator. */
21     public Precedence precedence() { return prec; }
22     }
23
24     public static final Operator GT = new Operator(">", Precedence.RELATIONAL);
25     public static final Operator LT = new Operator("<", Precedence.RELATIONAL);
26     public static final Operator EQ = new Operator("==", Precedence.EQUAL);
27     public static final Operator LE = new Operator("<=", Precedence.RELATIONAL);
28     public static final Operator GE = new Operator(">=", Precedence.RELATIONAL);
29     public static final Operator NE = new Operator("!=", Precedence.EQUAL);
30     public static final Operator COND_OR = new Operator("||", Precedence.COND_OR);
31     public static final Operator COND_AND = new Operator("&&", Precedence.COND_AND);
32     public static final Operator ADD = new Operator("+", Precedence.ADD);
33     public static final Operator SUB = new Operator("-", Precedence.ADD);
34     public static final Operator MUL = new Operator("*", Precedence.MUL);
35     public static final Operator DIV = new Operator("/", Precedence.MUL);
36     public static final Operator MOD = new Operator("%", Precedence.MUL);
37     public static final Operator BIT_OR = new Operator("|", Precedence.BIT_OR);
38     public static final Operator BIT_AND = new Operator("&", Precedence.BIT_AND);
39     public static final Operator BIT_XOR = new Operator("^", Precedence.BIT_XOR);
40     public static final Operator SHL = new Operator("<<", Precedence.SHIFT);
41     public static final Operator SHR = new Operator(">>", Precedence.SHIFT);
42     public static final Operator USHR = new Operator(">>>", Precedence.SHIFT);
43
44     /**
45      * Left child of the binary.
46      */

47     Expr left();
48
49     /**
50      * Set the left child of the binary.
51      */

52     Binary left(Expr left);
53
54     /**
55      * The binary's operator.
56      */

57     Operator operator();
58
59     /**
60      * Set the binary's operator.
61      */

62     Binary operator(Operator op);
63
64     /**
65      * Right child of the binary.
66      */

67     Expr right();
68
69     /**
70      * Set the right child of the binary.
71      */

72     Binary right(Expr right);
73
74     /**
75      * Returns true if the binary might throw an arithmetic exception,
76      * such as division by zero.
77      */

78     boolean throwsArithmeticException();
79
80     /**
81      * Set the precedence of the expression.
82      */

83     Binary precedence(Precedence precedence);
84 }
85
Popular Tags