6ce449540a67b830787c8a5d8ca810b2d59d841f
[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         class SpecParser {
68                 public static void main(String[] argvs)
69                 throws ParseException, TokenMgrError {
70                         SpecParser parser = new SpecParser(System.in);
71                         parser.Start();
72                         System.out.println("Parsing finished!");
73                 }
74         }
75 PARSER_END(SpecParser)
76
77 SKIP :
78 {
79         " "
80 |
81         "\n"
82 |
83         "\r"
84 |
85         "\t"
86 |
87         // "#" comment for the specification
88         <"#" (~["\n", "\r"])* (["\n", "\r"])>
89 |
90         // "//" comment for the specification
91         <"//" (~["\n", "\r"])* (["\n", "\r"])>
92 }
93
94 TOKEN :
95 {
96         <HEAD: "/**">
97 |
98         <TAIL: "*/">
99 |
100         <BEGIN: "@Begin">
101 |
102         <END: "@End">
103 |
104         <GLOBAL_DEFINE: "@Global_define:">
105 |
106         <INTERFACE_CLUSTER: "@Interface_cluster:">
107 |
108         <HAPPENS_BEFORE: "@Happens_before:">
109 |
110         <INTERFACE: "@Interface:">
111 |
112         <COMMIT_POINT_SET: "@Commit_point_set:">
113 |
114         <CONDITION: "@Condition:">
115 |
116         <HB_CONDITIONS: "@HB_condition:">
117 |
118         <ID: "@ID:">
119 |
120         <CHECK: "@Check:">
121 |
122         <ACTION: "@Action:">
123 |
124         <POST_ACTION: "@Post_action:">
125 |
126         <POST_CHECK: "@Post_check:">
127 |
128         <POTENTIAL_COMMIT_POINT_DEFINE: "@Potential_commit_point_define:">
129 |
130         <LABEL: "@Label:">
131 |
132         <COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
133 |
134         <COMMIT_POINT_DEFINE: "@Commit_point_define:">
135 |
136         <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
137 |
138         <#DIGIT: ["0"-"9"]>
139 |
140         <#NONZERO_DIGIT: ["1"-"9"]>
141 |
142         <#LETTER: ["a"-"z", "A"-"Z"]>
143 |
144         <#NUM: <NONZERO_DIGIT> <DIGIT>>
145 |
146         <IDENTIFIER: <LETTER> (<LETTER> | <DIGIT> | "_")>       
147 }
148
149 void Start() :
150 {}
151 {
152         Global_construct() <EOF>
153 }
154
155 void Global_construct() :
156 {}
157 {
158         <HEAD>
159                 <BEGIN> 
160                         Global_define() (Interface_cluster())? (Happens_before())?
161                 <END>
162         <TAIL>
163 }
164
165 void C_CPP_CODE() :
166 {}
167 {
168         <(~["@"])+>
169 }
170
171 void Global_define() :
172 {}
173 {
174         <GLOBAL_DEFINE> C_CPP_CODE()
175 }
176
177 void Conditional_interface() :
178 {}
179 {
180         <IDENTIFIER> (<"(" <IDENTIFIER> ")"> | "")
181 }
182
183 void Interface_cluster() :
184 {}
185 {
186         <IDENTIFIER> "=" "{" Conditional_interface() (",," Conditional_interface())* "}"
187 }
188
189 void Interface_clusters() :
190 {}
191 {
192         <INTERFACE_CLUSTER> (Interface_cluster())+
193 }
194
195 void Happens_before() :
196 {}
197 {
198         <HAPPENS_BEFORE> (Conditional_interface()  "->" Conditional_interface())+
199 }
200
201 void Interface() :
202 {}
203 {
204         <HEAD> 
205                 <BEGIN> 
206                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
207                 <END>
208         <TAIL>
209 }
210
211 void Potential_commit_point_define() :
212 {}
213 {
214         <HEAD> 
215                 <BEGIN> 
216                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
217                 <END>
218         <TAIL>
219 }
220
221
222 void Commit_point_define() :
223 {}
224 {
225         <HEAD> 
226                 <BEGIN> 
227                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
228                 <END>
229         <TAIL>
230 }
231
232
233 void Commit_point_define_check() :
234 {}
235 {
236         <HEAD> 
237                 <BEGIN> 
238                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
239                 <END>
240         <TAIL>
241 }