SpecExtractor.java seems to work
[cdsspec-compiler.git] / grammer / spec-compiler.jj
1 /* spec-compiler.jj Grammer definition for the specification */
2
3
4 /*
5         SPEC constructs:
6         Each construct should be embraced by /DOUBLE_STAR ... STAR/ annotation.
7         Within there, any line beginning with a "#" is a comment of the annotation.
8         Each constrcut should begin with @Begin and end with @End. Otherwise, the
9         annotation would be considered as normal comments of the source.
10         
11         a) Global construct
12         @Begin
13         @Global_define:
14                 ...
15         @Interface_cluster:
16                 ...
17         @Happens-before:
18                 ...
19         @End
20         
21         b) Interface construct
22         @Begin
23         @Interface: ...
24         @Commit_point_set:
25                 ...
26         @Condition: ... (Optional)
27         @ID: ... (Optional, use default ID)
28         @Check: (Optional)
29                 ...
30         @Action: (Optional)
31                 ...
32         @Post_action: (Optional)
33         @Post_check: (Optional)
34         @End
35
36         c) Potential commit construct
37         @Begin
38         @Potential_commit_point_define: ...
39         @Label: ...
40         @End
41
42         d) Commit point define construct
43         @Begin
44         @Commit_point_define_check: ...
45         @Label: ...
46         @End
47         
48                 OR
49
50         @Begin
51         @Commit_point_define: ...
52         @Potential_commit_point_label: ...
53         @Label: ...
54         @End
55 */
56
57
58
59 options {
60         STATIC = false;
61         JAVA_UNICODE_ESCAPE = true;
62 }
63
64 PARSER_BEGIN(SpecParser)
65 package edu.uci.eecs.specCompiler.grammerParser;
66
67 import java.io.FileInputStream;
68 import java.io.FileNotFoundException;
69
70         class SpecParser {
71                 public static void main(String[] argvs)
72                 throws ParseException, TokenMgrError {
73                         try {
74                                 FileInputStream fis = new FileInputStream("./grammer/spec.txt");
75                                 SpecParser parser = new SpecParser(fis);
76                                 parser.Start();
77                                 System.out.println("Parsing finished!");
78                         } catch (FileNotFoundException e) {
79                                 e.printStackTrace();
80                         }
81                 }
82         }
83 PARSER_END(SpecParser)
84
85 SKIP :
86 {
87         " "
88 |
89         "\n"
90 |
91         "\r"
92 |
93         "\r\n"
94 |
95         "\t"
96         /*
97 |
98         // "#" comment for the specification
99         <"#" (~["\n", "\r"])* (["\n", "\r"])>
100 |
101         // "//" comment for the specification
102         <"//" (~["\n", "\r"])* (["\n", "\r"])>
103         */
104 }
105
106 TOKEN :
107 {
108         <HEAD: "/**">
109 |
110         <TAIL: "*/">
111 |
112         <BEGIN: "@Begin">
113 |
114         <END: "@End">
115 |
116         <GLOBAL_DEFINE: "@Global_define:">
117 |
118         <INTERFACE_CLUSTER: "@Interface_cluster:">
119 |
120         <HAPPENS_BEFORE: "@Happens_before:">
121 |
122         <INTERFACE: "@Interface:">
123 |
124         <COMMIT_POINT_SET: "@Commit_point_set:">
125 |
126         <CONDITION: "@Condition:">
127 |
128         <HB_CONDITIONS: "@HB_condition:">
129 |
130         <ID: "@ID:">
131 |
132         <CHECK: "@Check:">
133 |
134         <ACTION: "@Action:">
135 |
136         <POST_ACTION: "@Post_action:">
137 |
138         <POST_CHECK: "@Post_check:">
139 |
140         <POTENTIAL_COMMIT_POINT_DEFINE: "@Potential_commit_point_define:">
141 |
142         <LABEL: "@Label:">
143 |
144         <COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
145 |
146         <COMMIT_POINT_DEFINE: "@Commit_point_define:">
147 |
148         <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
149 |
150         <#DIGIT: ["0"-"9"]>
151 |
152         <#LETTER: ["a"-"z", "A"-"Z"]>
153 |
154         <IDENTIFIER: <LETTER> (<LETTER> | <DIGIT> | "_")>       
155 }
156
157 void Start() :
158 {}
159 {
160         //Global_construct() <EOF>
161         <EOF>
162         //<IDENTIFIER> <EOF>
163 }
164
165 void Global_construct() :
166 {}
167 {
168         <HEAD>
169                 <BEGIN> 
170                         //Global_define() (Interface_cluster())? (Happens_before())?
171                 <END>
172         <TAIL>
173 }
174
175 void C_CPP_CODE() :
176 {String code;}
177 {
178         <(~["@"])+>
179 }
180
181 void Global_define() :
182 {}
183 {
184         <GLOBAL_DEFINE> C_CPP_CODE()
185 }
186
187 void Conditional_interface() :
188 {}
189 {
190         <IDENTIFIER> (<"(" <IDENTIFIER> ")"> | "")
191 }
192
193 void Interface_cluster() :
194 {}
195 {
196         <IDENTIFIER> "=" "{" Conditional_interface() (",," Conditional_interface())* "}"
197 }
198
199 void Interface_clusters() :
200 {}
201 {
202         <INTERFACE_CLUSTER> (Interface_cluster())+
203 }
204
205 void Happens_before() :
206 {}
207 {
208         <HAPPENS_BEFORE> (Conditional_interface()  "->" Conditional_interface())+
209 }
210
211 void Interface() :
212 {}
213 {
214         <TAIL>
215 }
216
217 void Potential_commit_point_define() :
218 {}
219 {
220         <HEAD> 
221                 <BEGIN> 
222                 <END>
223         <TAIL>
224 }
225
226
227 void Commit_point_define() :
228 {}
229 {
230         <HEAD> 
231                 <BEGIN> 
232                 <END>
233         <TAIL>
234 }
235
236
237 void Commit_point_define_check() :
238 {}
239 {
240         <HEAD> 
241                 <BEGIN> 
242                 <END>
243         <TAIL>
244 }