source: CIVL/mods/dev.civl.abc/grammar/fortran/OmpParserF08.g

main
Last change on this file was aad342c, checked in by Stephen Siegel <siegel@…>, 3 years ago

Performing huge refactor to incorporate ABC, GMC, and SARL into CIVL repo and use Java modules.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5664 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 6.3 KB
Line 
1parser grammar OmpParserF08;
2
3options
4{
5 language=Java;
6 tokenVocab=OmpLexerF08;
7 output=AST;
8}
9
10//import FortranParserExtras;
11
12tokens
13{
14 T_IDENTIFIER_LIST;
15 T_PARALLEL_FOR;
16 T_PARALLEL_SECTIONS;
17 T_UNIQUE_FOR;
18 T_UNIQUE_PARALLEL;
19 T_DATA_CLAUSE;
20 T_FOR_CLAUSE;
21}
22
23/* ANTLR 3.5 doesn't allow redefinition of headers in composite grammars.
24Our solution for this is: add the header (package, imported package)
25to the generated java file in ant.
26@header
27{
28package dev.civl.abc.front.fortran.old.parse;
29}*/
30
31@members {
32 @Override
33 public void displayRecognitionError(String[] tokenNames, RecognitionException e) {
34 String hdr = getErrorHeader(e);
35 String msg = getErrorMessage(e, tokenNames);
36
37 throw new RuntimeParseException(hdr+" "+msg, e.token);
38 }
39
40 @Override
41 public void emitErrorMessage(String msg) { // don't try to recover!
42 throw new RuntimeParseException(msg);
43 }
44}
45
46// openMP grammar : a bit old
47// missing some things, e.g., collapse, block, ...
48
49openmp_construct
50 :
51 parallel_for_directive
52 | parallel_sections_directive
53 | parallel_directive
54 | for_directive
55 | sections_directive
56 | single_directive
57 | master_directive
58 | critical_directive
59 | ordered_directive
60 | section_directive
61 | ompatomic_directive
62 | barrier_directive
63 | flush_directive
64 | threadprivate_directive
65 | end_directive
66 ;
67
68parallel_directive
69 : T_PARALLEL (p+=parallel_clause)*
70 -> ^(T_PARALLEL $p*)
71 ;
72
73parallel_clause
74 : unique_parallel_clause
75 | data_clause
76 ;
77
78master_directive
79 : T_MASTER -> ^(T_MASTER)
80 ;
81
82critical_directive
83 : T_CRITICAL (T_LPAREN id=T_IDENT T_RPAREN)?
84 -> ^(T_CRITICAL $id?)
85 ;
86
87sections_directive
88 : T_SECTIONS (s+=sections_clause)*
89 -> ^(T_SECTIONS $s*)
90 ;
91
92sections_clause
93 : data_clause
94 | nowait_directive
95 ;
96
97section_directive
98 : T_SECTION -> ^(T_SECTION)
99 ;
100
101parallel_for_directive
102 : T_PARALLEL T_DO p+=parallel_for_clause*
103 -> ^(T_PARALLEL_FOR $p*)
104 ;
105
106parallel_for_clause
107 : unique_parallel_clause
108 | unique_for_clause
109 | data_clause
110 ;
111
112parallel_sections_directive
113 : T_PARALLEL T_SECTIONS p+=parallel_sections_clause*
114 -> ^(T_PARALLEL_SECTIONS $p*)
115 ;
116
117parallel_sections_clause
118 : unique_parallel_clause
119 | data_clause
120 ;
121
122single_directive
123 : T_SINGLE s+=single_clause*
124 -> ^(T_SINGLE $s*)
125 ;
126
127single_clause
128 : data_clause
129 | nowait_directive
130 ;
131
132barrier_directive
133 : T_BARRIER -> ^(T_BARRIER)
134 ;
135
136ompatomic_directive
137 : T_OMPATOMIC c0=atomic_clasue? c1=seq_cst_clause?
138 -> ^(T_OMPATOMIC $c0? $c1?)
139 ;
140
141atomic_clasue
142 : T_READ | T_WRITE | T_UPDATE | T_CAPTURE
143 ;
144
145seq_cst_clause
146 : T_SEQ_CST
147 ;
148
149flush_directive
150 : T_FLUSH f=flush_vars?
151 -> ^(T_FLUSH $f?)
152 ;
153
154flush_vars
155 : T_LPAREN i=identifier_list T_RPAREN
156 -> ^(T_IDENTIFIER_LIST $i)
157 ;
158
159ordered_directive
160 : T_ORDERED -> ^(T_ORDERED)
161 ;
162
163nowait_directive
164 : T_NOWAIT -> ^(T_NOWAIT)
165 ;
166
167threadprivate_directive
168 : T_THD_PRIVATE T_LPAREN i=identifier_list T_RPAREN
169 -> ^(T_THD_PRIVATE $i)
170 ;
171
172for_directive
173 : T_DO (f+=for_clause)*
174 -> ^(T_DO $f*)
175 ;
176
177for_clause
178 : u=unique_for_clause -> ^(T_FOR_CLAUSE $u)
179 | d=data_clause -> ^(T_FOR_CLAUSE $d)
180 | n=nowait_directive -> ^(T_FOR_CLAUSE $n)
181 ;
182
183unique_for_clause
184 : T_ORDERED ->^(T_UNIQUE_FOR T_ORDERED)
185 | s1=schedule_clause -> ^(T_UNIQUE_FOR $s1)
186 | c=collapse_clause -> ^(T_UNIQUE_FOR $c)
187 ;
188
189schedule_clause
190 : T_SCHEDULE T_LPAREN s1=schedule_kind T_COMMA e=expression T_RPAREN
191 -> ^(T_SCHEDULE $s1 $e)
192 | T_SCHEDULE T_LPAREN s=schedule_kind T_RPAREN
193 -> ^(T_SCHEDULE $s)
194 ;
195
196collapse_clause
197 :
198 T_COLLAPSE T_LPAREN i=T_DIGIT_STRING T_RPAREN
199 -> ^(T_COLLAPSE $i)
200 ;
201
202schedule_kind
203 : T_STATIC -> ^(T_STATIC)
204 | T_DYNAMIC -> ^(T_DYNAMIC)
205 | T_GUIDED -> ^(T_GUIDED)
206 | T_RUNTIME -> ^(T_RUNTIME)
207 ;
208
209unique_parallel_clause
210 : i=if_clause
211 -> ^(T_UNIQUE_PARALLEL $i)
212 | n=num_threads_clause
213 -> ^(T_UNIQUE_PARALLEL $n)
214 ;
215
216if_clause
217 : T_IF T_LPAREN e1=expression T_RPAREN
218 -> ^(T_IF $e1)
219 ;
220
221num_threads_clause
222 : T_NUM_THREADS T_LPAREN e2=expression T_RPAREN
223 -> ^(T_NUM_THREADS $e2)
224 ;
225
226data_clause
227 : d1=private_clause
228 -> ^(T_DATA_CLAUSE $d1)
229 | d2=firstprivate_clause
230 -> ^(T_DATA_CLAUSE $d2)
231 | d3=lastprivate_clause
232 -> ^(T_DATA_CLAUSE $d3)
233 | d4=shared_clause
234 -> ^(T_DATA_CLAUSE $d4)
235 | d5=default_clause
236 -> ^(T_DATA_CLAUSE $d5)
237 | d6=reduction_clause
238 -> ^(T_DATA_CLAUSE $d6)
239 | d7=copyin_clause
240 -> ^(T_DATA_CLAUSE $d7)
241 | d8=copyprivate_clause
242 -> ^(T_DATA_CLAUSE $d8)
243 ;
244
245private_clause
246 : T_PRIVATE T_LPAREN i1=identifier_list T_RPAREN
247 -> ^(T_PRIVATE $i1)
248 ;
249
250firstprivate_clause
251 : T_FST_PRIVATE T_LPAREN i2=identifier_list T_RPAREN
252 -> ^(T_FST_PRIVATE $i2)
253 ;
254
255lastprivate_clause
256 : T_LST_PRIVATE T_LPAREN i3=identifier_list T_RPAREN
257 -> ^(T_LST_PRIVATE $i3)
258 ;
259
260shared_clause
261 : T_SHARED T_LPAREN i4=identifier_list T_RPAREN
262 -> ^(T_SHARED $i4)
263 ;
264
265default_clause
266 : T_DEFAULT T_LPAREN T_SHARED T_RPAREN
267 -> ^(T_DEFAULT T_SHARED)
268 | T_DEFAULT T_LPAREN T_PRIVATE T_RPAREN
269 -> ^(T_DEFAULT T_NONE)
270 | T_DEFAULT T_LPAREN T_NONE T_RPAREN
271 -> ^(T_DEFAULT T_NONE)
272 ;
273
274reduction_clause
275 : T_REDUCTION T_LPAREN r=reduction_operator T_COLON i5=identifier_list T_RPAREN
276 -> ^(T_REDUCTION $r $i5)
277 ;
278
279copyin_clause
280 : T_COPYIN T_LPAREN i6=identifier_list T_RPAREN
281 -> ^(T_COPYIN $i6)
282 ;
283
284copyprivate_clause
285 : T_COPYPRIVATE T_LPAREN i7=identifier_list T_RPAREN
286 -> ^(T_COPYPRIVATE $i7)
287 ;
288
289reduction_operator
290 : T_PLUS -> ^(T_PLUS)
291 | T_ASTERISK -> ^(T_ASTERISK)
292 | T_MINUS -> ^(T_MINUS)
293 | T_AMPERSAND -> ^(T_AMPERSAND)
294 | T_BITXOR -> ^(T_BITXOR)
295 | T_BITOR -> ^(T_BITOR)
296 | T_AND -> ^(T_AND)
297 | T_OR -> ^(T_OR)
298 | T_IDENT -> ^(T_IDENT)
299 ;
300
301identifier_list
302 :
303 i1=T_IDENT ( T_COMMA i2+=T_IDENT)*
304 -> ^(T_IDENTIFIER_LIST $i1 $i2*)
305 ;
306
307//EXPRESSION:
308expression
309 :
310 (i1=T_IDENT)
311 -> ^($i1)
312 ;
313
314end_directive
315 :
316 T_END kl=keyword_list
317 -> ^(T_END $kl)
318 ;
319
320keyword_list
321 :
322 T_PARALLEL -> ^(T_PARALLEL)
323 |T_DO -> ^(T_DO)
324 |T_SECTIONS -> ^(T_SECTIONS)
325 |T_SINGLE -> ^(T_SINGLE)
326 |T_MASTER -> ^(T_MASTER)
327 |T_CRITICAL -> ^(T_CRITICAL)
328 |T_ORDERED -> ^(T_ORDERED)
329 |T_SECTION -> ^(T_SECTION)
330 |T_OMPATOMIC -> ^(T_OMPATOMIC)
331 |T_BARRIER -> ^(T_BARRIER)
332 |T_FLUSH -> ^(T_FLUSH)
333 |T_THD_PRIVATE -> ^(T_THD_PRIVATE)
334 ;
335
Note: See TracBrowser for help on using the repository browser.