01: /*
02: * Copyright (C) Chaperon. All rights reserved.
03: * -------------------------------------------------------------------------
04: * This software is published under the terms of the Apache Software License
05: * version 1.1, a copy of which has been included with this distribution in
06: * the LICENSE file.
07: */
08:
09: package net.sourceforge.chaperon.model.grammar;
10:
11: import java.io.Serializable;
12:
13: /**
14: * This class represents a associativity for a terminal of production.
15: *
16: * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
17: * @version CVS $Id: Associativity.java,v 1.3 2003/12/09 19:55:52 benedikta Exp $
18: */
19: public class Associativity implements Serializable {
20: /** Left associativity */
21: public static final Associativity LEFT = new Associativity("left");
22:
23: /** Right associativity */
24: public static final Associativity RIGHT = new Associativity("right");
25:
26: /** Non associativity */
27: public static final Associativity NONASSOC = new Associativity(
28: "nonassoc");
29: private String value = null;
30:
31: /**
32: * Create a new associativity object.
33: *
34: * @param value left | right | nonassoc are allowed
35: */
36: public Associativity(String value) {
37: if ((value.equals("left")) || (value.equals("right"))
38: || (value.equals("nonassoc")))
39: this .value = value;
40: else
41: throw new IllegalArgumentException("Type not recognized");
42: }
43:
44: /**
45: * Compare with another object.
46: *
47: * @param o Other object
48: *
49: * @return True, if the associative object has the same associativity
50: */
51: public boolean equals(Object o) {
52: if (o == this )
53: return true;
54:
55: if (o instanceof Associativity) {
56: Associativity assoc = (Associativity) o;
57:
58: return (assoc.value.equals(value));
59: }
60:
61: return false;
62: }
63:
64: /**
65: * Returns the String representation of this associativity
66: *
67: * @return String representation.
68: */
69: public String toString() {
70: return value;
71: }
72: }
|