01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.js.ast;
17:
18: /**
19: * A JavaScript operator.
20: */
21: public abstract class JsOperator {
22:
23: protected static final int LEFT = 0x01;
24: protected static final int INFIX = 0x02;
25: protected static final int POSTFIX = 0x04;
26: protected static final int PREFIX = 0x08;
27:
28: private final int mask;
29:
30: private final int precedence;
31:
32: private final String symbol;
33:
34: protected JsOperator(String symbol, int precedence, int mask) {
35: this .symbol = symbol;
36: this .precedence = precedence;
37: this .mask = mask;
38: }
39:
40: public int getPrecedence() {
41: return precedence;
42: }
43:
44: public String getSymbol() {
45: return symbol;
46: }
47:
48: public abstract boolean isKeyword();
49:
50: public boolean isLeftAssociative() {
51: return (mask & LEFT) != 0;
52: }
53:
54: public boolean isPrecedenceLessThan(JsOperator other) {
55: return precedence < other.precedence;
56: }
57:
58: public boolean isValidInfix() {
59: return (mask & INFIX) != 0;
60: }
61:
62: public boolean isValidPostfix() {
63: return (mask & POSTFIX) != 0;
64: }
65:
66: public boolean isValidPrefix() {
67: return (mask & PREFIX) != 0;
68: }
69:
70: @Override
71: public String toString() {
72: return symbol;
73: }
74: }
|