Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 48655f6df884f74649fade48bca7e969d9d32da7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
-----------------------------------------------------------------------------------
-- Copyright (c) 2006, 2007 IBM Corporation and others.
-- All rights reserved. This program and the accompanying materials
-- are made available under the terms of the Eclipse Public License v1.0
-- which accompanies this distribution, and is available at
-- http://www.eclipse.org/legal/epl-v10.html
--
-- Contributors:
--     IBM Corporation - initial API and implementation
-----------------------------------------------------------------------------------


$Define
	$build_action_class /. UPCParserAction ./
	$node_factory_create_expression /. UPCASTNodeFactory.DEFAULT_INSTANCE ./
$End


$Globals
/.
import org.eclipse.cdt.core.dom.parser.upc.UPCASTNodeFactory;
import org.eclipse.cdt.core.dom.parser.upc.UPCParserAction;
import org.eclipse.cdt.core.dom.upc.ast.IUPCASTKeywordExpression;
import org.eclipse.cdt.core.dom.upc.ast.IUPCASTSynchronizationStatement;
import org.eclipse.cdt.core.dom.upc.ast.IUPCASTUnarySizeofExpression;
import org.eclipse.cdt.core.dom.lrparser.lpgextensions.FixedBacktrackingParser;
./
$End


$Terminals  -- Additional keywords defined by UPC
	MYTHREAD
	THREADS
	UPC_MAX_BLOCKSIZE
	relaxed
	shared
	strict
	upc_barrier 
	upc_localsizeof
	upc_blocksizeof 
	upc_elemsizeof 
	upc_notify
	upc_fence 
	upc_wait
	upc_forall
$End



$Rules  -- UPC grammar extensions to C99

-----------------------------------------------------------------------------------
-- Expressions
-----------------------------------------------------------------------------------


literal
    ::= 'MYTHREAD'
            /. $Build  consumeKeywordExpression(IUPCASTKeywordExpression.kw_mythread); $EndBuild ./
      | 'THREADS'
            /. $Build  consumeKeywordExpression(IUPCASTKeywordExpression.kw_threads); $EndBuild ./
      | 'UPC_MAX_BLOCKSIZE'
            /. $Build  consumeKeywordExpression(IUPCASTKeywordExpression.kw_upc_max_block_size); $EndBuild ./
            

-- causes ambiguities because of no type information, solution is SGLR
unary_expression
    ::= 'upc_localsizeof' unary_expression
          /. $Build  consumeExpressionUnarySizeofOperator(IUPCASTUnarySizeofExpression.upc_localsizeof); $EndBuild ./
      | 'upc_localsizeof' '(' type_name ')'
          /. $Build  consumeExpressionSizeofTypeId(IUPCASTUnarySizeofExpression.upc_localsizeof); $EndBuild ./
      | 'upc_blocksizeof' unary_expression
          /. $Build  consumeExpressionUnarySizeofOperator(IUPCASTUnarySizeofExpression.upc_blocksizeof); $EndBuild ./
      | 'upc_blocksizeof' '(' type_name ')'
          /. $Build  consumeExpressionSizeofTypeId(IUPCASTUnarySizeofExpression.upc_blocksizeof); $EndBuild ./
      | 'upc_elemsizeof'  unary_expression
          /. $Build  consumeExpressionUnarySizeofOperator(IUPCASTUnarySizeofExpression.upc_elemsizeof); $EndBuild ./
      | 'upc_elemsizeof'  '(' type_name ')'
          /. $Build  consumeExpressionSizeofTypeId(IUPCASTUnarySizeofExpression.upc_elemsizeof); $EndBuild ./
      
      
-----------------------------------------------------------------------------------
-- Declarations
-----------------------------------------------------------------------------------


type_qualifier
    ::= shared_type_qualifier
      | reference_type_qualifier

-- causes ambiguities in parameter declarations, inherant in grammar
-- for example: int foo(int shared []);
-- does the [] bind to shared or is it shared with infinite block size array?
-- TODO: probably just resolved in the same way as dangling else

shared_type_qualifier
    ::= 'shared' layout_qualifier  -- don't consume anything, the presense of the 
                                   -- layout_qualifier will determine that 'shared' token was encountered
      | 'shared'   /. $Build  consumeToken();  $EndBuild ./

reference_type_qualifier
    ::= 'relaxed'  /. $Build  consumeToken();  $EndBuild ./
      | 'strict'   /. $Build  consumeToken();  $EndBuild ./

layout_qualifier
    ::= '[' constant_expression ']'
         /. $Build  consumeLayoutQualifier(true, false);  $EndBuild ./
      | '[' '*' ']'
         /. $Build  consumeLayoutQualifier(false, true);  $EndBuild ./
      | '[' ']'
         /. $Build  consumeLayoutQualifier(false, false);  $EndBuild ./



-----------------------------------------------------------------------------------
-- Statements
-----------------------------------------------------------------------------------

statement
     ::= synchronization_statement

synchronization_statement
     ::= 'upc_notify' expression ';'
           /. $Build  consumeStatementSynchronizationStatement(IUPCASTSynchronizationStatement.st_upc_notify, true); $EndBuild ./
       | 'upc_notify' ';'
           /. $Build  consumeStatementSynchronizationStatement(IUPCASTSynchronizationStatement.st_upc_notify, false); $EndBuild ./
       | 'upc_wait' expression ';'
           /. $Build  consumeStatementSynchronizationStatement(IUPCASTSynchronizationStatement.st_upc_wait, true); $EndBuild ./
       | 'upc_wait' ';'
           /. $Build  consumeStatementSynchronizationStatement(IUPCASTSynchronizationStatement.st_upc_wait, false); $EndBuild ./
       | 'upc_barrier' expression ';'
           /. $Build  consumeStatementSynchronizationStatement(IUPCASTSynchronizationStatement.st_upc_barrier, true); $EndBuild ./
       | 'upc_barrier' ';'
           /. $Build  consumeStatementSynchronizationStatement(IUPCASTSynchronizationStatement.st_upc_barrier, false); $EndBuild ./
       | 'upc_fence' ';'
           /. $Build  consumeStatementSynchronizationStatement(IUPCASTSynchronizationStatement.st_upc_fence, false); $EndBuild ./
       
       
iteration_statement
    ::= 'upc_forall' '(' expression ';' expression ';' expression ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, true, true, true); $EndBuild ./
            
      | 'upc_forall' '(' expression ';' expression ';' expression ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, true, true, false); $EndBuild ./
            
      | 'upc_forall' '(' expression ';' expression ';'            ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, true, false, true); $EndBuild ./
            
      | 'upc_forall' '(' expression ';' expression ';'            ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, true, false, false); $EndBuild ./
            
      | 'upc_forall' '(' expression ';'            ';' expression ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, false, true, true); $EndBuild ./
            
      | 'upc_forall' '(' expression ';'            ';' expression ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, false, true, false); $EndBuild ./
            
      | 'upc_forall' '(' expression ';'            ';'            ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, false, false, true); $EndBuild ./
            
      | 'upc_forall' '(' expression ';'            ';'            ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, false, false, false); $EndBuild ./
            
      | 'upc_forall' '('            ';' expression ';' expression ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(false, true, true, true); $EndBuild ./
            
      | 'upc_forall' '('            ';' expression ';' expression ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(false, true, true, false); $EndBuild ./
            
      | 'upc_forall' '('            ';' expression ';'            ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(false, true, false, true); $EndBuild ./
            
      | 'upc_forall' '('            ';' expression ';'            ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(false, true, false, false); $EndBuild ./
            
      | 'upc_forall' '('            ';'            ';' expression ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(false, false, true, true); $EndBuild ./
            
      | 'upc_forall' '('            ';'            ';' expression ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(false, false, true, false); $EndBuild ./
            
      | 'upc_forall' '('            ';'            ';'            ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(false, false, false, true); $EndBuild ./
            
      | 'upc_forall' '('            ';'            ';'            ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(false, false, false, false); $EndBuild ./
      
      | 'upc_forall' '(' declaration expression ';' expression ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, true, true, true); $EndBuild ./
            
      | 'upc_forall' '(' declaration expression ';' expression ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, true, true, false); $EndBuild ./
            
      | 'upc_forall' '(' declaration expression ';'            ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, true, false, true); $EndBuild ./
            
      | 'upc_forall' '(' declaration expression ';'            ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, true, false, false); $EndBuild ./
            
      | 'upc_forall' '(' declaration            ';' expression ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, false, true, true); $EndBuild ./
            
      | 'upc_forall' '(' declaration            ';' expression ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, false, true, false); $EndBuild ./
            
      | 'upc_forall' '(' declaration            ';'            ';' affinity ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, false, false, true); $EndBuild ./
            
      | 'upc_forall' '(' declaration            ';'            ';'          ')' statement
            /. $Build  consumeStatementUPCForallLoop(true, false, false, false); $EndBuild ./

affinity
    ::= expression
      | 'continue'
          /. $Build  consumeToken();  $EndBuild ./

$End


Back to the top