KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > beaver > spec > GrammarSymbol


1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * This file is part of Beaver Parser Generator. *
3  * Copyright (C) 2003,2004 Alexander Demenchuk <alder@softanvil.com>. *
4  * All rights reserved. *
5  * See the file "LICENSE" for the terms and conditions for copying, *
6  * distribution and modification of Beaver. *
7  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

8
9 package beaver.spec;
10
11 import java.util.Comparator JavaDoc;
12
13 /**
14  * Represents symbols of the grammar.
15  */

16 public abstract class GrammarSymbol
17 {
18     /** This symbol's ID */
19     public short id;
20     
21     /** Name of the symbol */
22     public final String JavaDoc name;
23
24     /** The type of data held by this symbol. */
25     public String JavaDoc type;
26     
27     /** Number of times this symbol is referenced in productions */
28     public int nrefs;
29     
30     GrammarSymbol(String JavaDoc name)
31     {
32         this.name = name;
33     }
34
35     GrammarSymbol(String JavaDoc name, String JavaDoc type)
36     {
37         this.name = name;
38         this.type = type;
39     }
40     
41     public String JavaDoc toString()
42     {
43         return name;
44     }
45     
46     public static final Comparator JavaDoc NUMBER_OF_REFERENCES_COMPARATOR = new Comparator JavaDoc()
47     {
48         public int compare(Object JavaDoc sym1, Object JavaDoc sym2)
49         {
50             return ((GrammarSymbol) sym2).nrefs - ((GrammarSymbol) sym1).nrefs;
51         }
52     };
53 }
54
Popular Tags