KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ppg > spec > Spec


1 package ppg.spec;
2
3 import java.util.*;
4 import ppg.*;
5 import ppg.code.*;
6 import ppg.parse.*;
7
8 public abstract class Spec implements Unparse
9 {
10     protected String JavaDoc packageName;
11     protected Vector imports, symbols, prec;
12     protected InitCode initCode;
13     protected ActionCode actionCode;
14     protected ParserCode parserCode;
15     protected ScanCode scanCode;
16     protected PPGSpec child;
17     
18     public Spec () {
19         initCode = null;
20         actionCode = null;
21         parserCode = null;
22         scanCode = null;
23         child = null;
24     }
25     
26     public void setPkgName (String JavaDoc pkgName) {
27         if (pkgName != null)
28             packageName = pkgName;
29     }
30     
31     public void replaceCode (Vector codeParts) {
32         if (codeParts == null)
33             return;
34         
35         Code code=null;
36         for (int i=0; i < codeParts.size(); i++) {
37             try {
38                 code = (Code) codeParts.elementAt(i);
39                 if (code instanceof ActionCode && code != null) {
40                     actionCode = (ActionCode) code.clone();
41                 } else if (code instanceof InitCode && code != null) {
42                     initCode = (InitCode) code.clone();
43                 } else if (code instanceof ParserCode && code != null) {
44                     parserCode = (ParserCode) code.clone();
45                 } else { // must be ScanCode
46
if (code != null)
47                         scanCode = (ScanCode) code.clone();
48                 }
49             } catch (Exception JavaDoc e) {
50                 System.err.println(PPG.HEADER+" Spec::replaceCode(): not a code segment "+
51                                    "found in code Vector: "+
52                                    ((code == null) ? "null" : code.toString()));
53                 System.exit(1);
54             }
55         }
56     }
57     
58     public void addImports (Vector imp) {
59         if (imp == null)
60             return;
61         
62         for (int i=0; i < imp.size(); i++) {
63             imports.addElement(imp.elementAt(i));
64         }
65     }
66     
67     public void setChild (PPGSpec childSpec) {
68         child = childSpec;
69     }
70     
71     // default action is to do nothing: as CUP does
72
public void parseChain(String JavaDoc basePath) {}
73
74     /**
75      * Combine the chain of inheritance into one CUP spec
76      */

77     public abstract CUPSpec coalesce() throws PPGError;
78     
79 }
80
Popular Tags