110dcb9c4979d84b5c8f4322ffef46e91a171a6f
[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         <EQUALS: "=">
157 |
158         <LEFT_PARAN: "{">
159 |
160         <RIGHT_PARAN: "}">
161 |
162         <HB_SYMBOL: "->">
163 |
164         <COMMA: ",">
165 }
166
167 void Start() :
168 {}
169 {
170         //Global_construct() <EOF>
171         <IDENTIFIER> <EOF>
172         //<IDENTIFIER> C_CPP_CODE() <EOF>
173 }
174
175 void Global_construct() :
176 {}
177 {
178         <HEAD>
179                 <BEGIN> 
180                         Global_define() (Interface_cluster())? (Happens_before())?
181                 <END>
182         <TAIL>
183 }
184
185 /*
186 void C_CPP_CODE() :
187 {}
188 {
189         <(~["@"])+>
190 }
191 */
192 void Global_define() :
193 {}
194 {
195         <GLOBAL_DEFINE> //C_CPP_CODE()
196 }
197
198 void Conditional_interface() :
199 {}
200 {
201         <IDENTIFIER> (<"(" <IDENTIFIER> ")">)*
202 }
203
204 void Interface_cluster() :
205 {}
206 {
207         <IDENTIFIER> <EQUALS> <LEFT_PARAN>
208                 Conditional_interface() (<COMMA> Conditional_interface())*
209         <RIGHT_PARAN>
210 }
211
212 void Interface_clusters() :
213 {}
214 {
215         <INTERFACE_CLUSTER> (Interface_cluster())+
216 }
217
218 void Happens_before() :
219 {}
220 {
221         <HAPPENS_BEFORE> (Conditional_interface() <HB_SYMBOL> Conditional_interface())+
222 }
223
224 void Interface() :
225 {}
226 {
227         <TAIL>
228 }
229
230 void Potential_commit_point_define() :
231 {}
232 {
233         <HEAD> 
234                 <BEGIN> 
235                 <END>
236         <TAIL>
237 }
238
239
240 void Commit_point_define() :
241 {}
242 {
243         <HEAD> 
244                 <BEGIN> 
245                 <END>
246         <TAIL>
247 }
248
249
250 void Commit_point_define_check() :
251 {}
252 {
253         <HEAD> 
254                 <BEGIN> 
255                 <END>
256         <TAIL>
257 }