KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ast > Precedence


1 package polyglot.ast;
2
3 import polyglot.util.Enum;
4
5 /**
6  * Constants defining the precedence of an expression. Higher
7  * values denote higher precedence (i.e., tighter binding).
8  */

9 public class Precedence extends Enum JavaDoc {
10     private int value;
11
12     public Precedence(String JavaDoc name, int value) {
13     super("prec_" + name);
14     this.value = value;
15     }
16
17     public int hashCode() {
18         return value;
19     }
20
21     /** Returns true if this and p have the same precedence. */
22     public boolean equals(Object JavaDoc o) {
23         return o instanceof Precedence && equals((Precedence) o);
24     }
25
26     /** Returns true if this and p have the same precedence. */
27     public boolean equals(Precedence p) {
28     return value == p.value;
29     }
30
31     /** Returns true if this binds tighter than p. */
32     public boolean isTighter(Precedence p) {
33     return value < p.value;
34     }
35
36     /** The precedence of a literal */
37     public static final Precedence LITERAL = new Precedence("literal", 0);
38     /** The precedence of a unary expression. */
39     public static final Precedence UNARY = new Precedence("unary", 10);
40     /** The precedence of a cast expression. */
41     public static final Precedence CAST = new Precedence("cast", 10);
42     /** The precedence of a <code>*</code>, <code>/</code>, or <code>%</code> expression. */
43     public static final Precedence MUL = new Precedence("*", 20);
44     /** The precedence of a <code>+</code> when applied to Strings. This is of higher precedence than <code>+</code> applied to numbers. */
45     public static final Precedence STRING_ADD = new Precedence("string+", 30);
46     /** The precedence of a <code>+</code> when applied to numbers, and the precedence of <code>-</code>. */
47     public static final Precedence ADD = new Precedence("+", 40);
48     /** The precedence of the shift expressions <code>&lt;&lt;</code>, <code>&gt;&gt;</code>, and <code>&gt;&gt;&gt;</code>. */
49     public static final Precedence SHIFT = new Precedence("<<", 50);
50     /** The precedence of the relational expressions <code>&lt;</code>, <code>&gt;</code>, <code>&lt;=</code>, and <code>&gt;=</code>. */
51     public static final Precedence RELATIONAL = new Precedence("<", 60);
52     /** The precedence of <code>instanceof</code> expressions. */
53     public static final Precedence INSTANCEOF = new Precedence("isa", 70);
54     /** The precedence of equality operators. That is, precedence of <code>==</code> and <code>!=</code> expressions. */
55     public static final Precedence EQUAL = new Precedence("==", 80);
56     /** The precedence of bitwise AND (<code>&amp;<code>) expressions. */
57     public static final Precedence BIT_AND = new Precedence("&", 90);
58     /** The precedence of bitwise XOR (<code>^<code>) expressions. */
59     public static final Precedence BIT_XOR = new Precedence("^", 100);
60     /** The precedence of bitwise OR (<code>|<code>) expressions. */
61     public static final Precedence BIT_OR = new Precedence("|", 110);
62     /** The precedence of conditional AND (<code>&&<code>) expressions. */
63     public static final Precedence COND_AND = new Precedence("&&", 120);
64     /** The precedence of conditional OR (<code>||<code>) expressions. */
65     public static final Precedence COND_OR = new Precedence("||", 130);
66     /** The precedence of ternary conditional expressions. */
67     public static final Precedence CONDITIONAL = new Precedence("?:", 140);
68     /** The precedence of assignment expressions. */
69     public static final Precedence ASSIGN = new Precedence("=", 130);
70     /** The precedence of all other expressions. This has the lowest precedence to ensure the expression is parenthesized on output. */
71     public static final Precedence UNKNOWN = new Precedence("unknown", 999);
72 }
73
Popular Tags