965e4f5fabc1951becf1361d8b500824f715fb24
[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
91 TOKEN :
92 {
93         <HEAD: "/**">
94 |
95         <TAIL: "*/">
96 |
97         <BEGIN: "@Begin">
98 |
99         <END: "@End">
100 |
101         <GLOBAL_DEFINE: "@Global_define:">
102 |
103         <INTERFACE_CLUSTER: "@Interface_cluster:">
104 |
105         <HAPPENS_BEFORE: "@Happens_before:">
106 |
107         <INTERFACE: "@Interface:">
108 |
109         <COMMIT_POINT_SET: "@Commit_point_set:">
110 |
111         <CONDITION: "@Condition:">
112 |
113         <NUM_OR_EMPTY: ["1"-"9"](["0"-"9"])+ | "">
114 |
115         <ONE_HB_CONDITION: "@HB_condition:" <NUM_OR_EMPTY> (~["@", "#", "$"])+> 
116 |
117         <ALL_HB_CONDITIONS: (<ONE_HB_CONDITION>)*>
118 |
119         <ID: "@ID:">
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 |
135         <COMMIT_POINT_DEFINE: "@Commit_point_define:">
136 |
137         <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
138 |
139         <IDENTIFIER: (["a"-"z", "A"-"Z", "_"]) (["0"-"9", "a"-"z", "A"-"Z", "_"])*>
140 }
141
142 void Start() :
143 {}
144 {
145         <EOF>
146 }
147
148 void Global_construct() :
149 {}
150 {
151         <HEAD> 
152                 <BEGIN> 
153                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
154                 <END>
155         <TAIL>
156 }
157
158 void C_CPP_CODE() :
159 {}
160 {
161         <(~["@", "#", "$"])+>
162 }
163
164 void Global_define() :
165 {}
166 {
167         <GLOBAL_DEFINE> C_CPP_CODE()
168 }
169
170 void Conditional_interface() :
171 {}
172 {
173         <IDENTIFIER> (<"(" <IDENTIFIER> ")"> | "")
174 }
175
176 void Interface_cluster() :
177 {}
178 {
179         <IDENTIFIER> "=" "{" Conditional_interface() (",," Conditional_interface())* "}"
180 }
181
182 void Interface_clusters() :
183 {}
184 {
185         <INTERFACE_CLUSTER> (Interface_cluster())+
186 }
187
188 void Happens_before() :
189 {}
190 {
191         <HEAD> 
192                 <BEGIN> 
193                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
194                 <END>
195         <TAIL>
196 }
197
198 void Interface() :
199 {}
200 {
201         <HEAD> 
202                 <BEGIN> 
203                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
204                 <END>
205         <TAIL>
206 }
207
208 void Potential_commit_point_define() :
209 {}
210 {
211         <HEAD> 
212                 <BEGIN> 
213                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
214                 <END>
215         <TAIL>
216 }
217
218
219 void Commit_point_define() :
220 {}
221 {
222         <HEAD> 
223                 <BEGIN> 
224                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
225                 <END>
226         <TAIL>
227 }
228
229
230 void Commit_point_define_check() :
231 {}
232 {
233         <HEAD> 
234                 <BEGIN> 
235                         <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
236                 <END>
237         <TAIL>
238 }