KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ppg > atoms > Precedence


1 package ppg.atoms;
2
3 import java.util.*;
4
5 public class Precedence
6 {
7     public static final int LEFT = 0;
8     public static final int RIGHT = 1;
9     public static final int NONASSOC = 2;
10     
11     private int type;
12     private Vector symbols;
13     
14     public Precedence(int type, Vector syms) {
15         this.type = type;
16         symbols = syms;
17     }
18     
19     public Object JavaDoc clone () {
20         Vector newSyms = new Vector();
21         for (int i=0; i < symbols.size(); i++) {
22             newSyms.addElement( ((GrammarSymbol)symbols.elementAt(i)).clone() );
23         }
24         return new Precedence(type, newSyms);
25     }
26     
27     public String JavaDoc toString () {
28         String JavaDoc result = "precedence ";
29         switch (type) {
30             case (LEFT): result += "left "; break;
31             case (RIGHT): result += "right "; break;
32             case (NONASSOC): result += "nonassoc "; break;
33         }
34
35         for (int i=0; i < symbols.size(); i++) {
36             result += symbols.elementAt(i);
37             if (i < symbols.size() - 1)
38                 result += ", ";
39         }
40         return result + ";";
41     }
42 }
43
Popular Tags