Skip to content

Latest commit

 

History

History
703 lines (613 loc) · 38.8 KB

mojoshader_parser_hlsl.lemon

File metadata and controls

703 lines (613 loc) · 38.8 KB
 
Feb 27, 2009
Feb 27, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* MojoShader; generate shader programs from bytecode of compiled
* Direct3D shaders.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
// This is a Lemon Parser grammar for HLSL. It is based on an ANSI C YACC
// grammar by Jeff Lee: http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
// Lemon is here: http://www.hwaci.com/sw/lemon/ ... the source is included
// with MojoShader, and built with the library, so you don't have to track
// down the dependency.
// HLSL syntax is described, informally, here:
// http://msdn.microsoft.com/en-us/library/bb509615(VS.85).aspx
%name ParseHLSL
Aug 26, 2009
Aug 26, 2009
22
23
// Some shift-reduce conflicts are basically unavoidable, but if the final
// conflict count matches this value, we consider it known and acceptable.
Aug 26, 2009
Aug 26, 2009
24
%expect 2
Aug 26, 2009
Aug 26, 2009
25
Feb 27, 2009
Feb 27, 2009
26
27
%start_symbol shader
%token_prefix TOKEN_HLSL_
Aug 23, 2009
Aug 23, 2009
28
%token_type { TokenData }
Feb 27, 2009
Feb 27, 2009
29
30
31
%extra_argument { Context *ctx }
%include {
Feb 28, 2009
Feb 28, 2009
32
33
34
#ifndef __MOJOSHADER_HLSL_COMPILER__
#error Do not compile this file directly.
#endif
35
}
Feb 27, 2009
Feb 27, 2009
36
Aug 23, 2009
Aug 23, 2009
37
%syntax_error {
Feb 19, 2010
Feb 19, 2010
38
39
// !!! FIXME: make this a proper fail() function.
ctx->isfail = 1;
Aug 23, 2009
Aug 23, 2009
40
41
42
fprintf(stderr,"Syntax error\n");
}
Feb 27, 2009
Feb 27, 2009
43
%parse_failure {
Feb 9, 2010
Feb 9, 2010
44
45
// !!! FIXME: make this a proper fail() function.
ctx->isfail = 1;
Feb 27, 2009
Feb 27, 2009
46
47
48
49
fprintf(stderr,"Giving up. Parser is hopelessly lost...\n");
}
%stack_overflow {
Feb 9, 2010
Feb 9, 2010
50
51
// !!! FIXME: make this a proper fail() function.
ctx->isfail = 1;
Feb 27, 2009
Feb 27, 2009
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
fprintf(stderr,"Giving up. Parser stack overflow\n");
}
// operator precedence (matches C spec)...
%left COMMA.
%right ASSIGN ADDASSIGN SUBASSIGN MULASSIGN DIVASSIGN MODASSIGN LSHIFTASSIGN
RSHIFTASSIGN ANDASSIGN ORASSIGN XORASSIGN.
%right QUESTION.
%left OROR.
%left ANDAND.
%left OR.
%left XOR.
%left AND.
%left EQL NEQ.
%left LT LEQ GT GEQ.
%left LSHIFT RSHIFT.
%left PLUS MINUS.
%left STAR SLASH PERCENT.
%right TYPECAST EXCLAMATION COMPLEMENT MINUSMINUS PLUSPLUS.
%left DOT LBRACKET RBRACKET LPAREN RPAREN.
Feb 27, 2009
Feb 27, 2009
74
75
76
77
// bump up the precedence of ELSE, to avoid shift/reduce conflict on the
// usual "dangling else ambiguity" ...
%right ELSE.
Feb 27, 2009
Feb 27, 2009
78
79
80
// The rules...
Feb 19, 2010
Feb 19, 2010
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
shader ::= compilation_units(B). { assert(ctx->ast == NULL); ctx->ast = B; }
%type compilation_units { CompilationUnit * }
%destructor compilation_units { delete_compilation_unit(ctx, $$); }
compilation_units(A) ::= compilation_unit(B). { A = B; }
compilation_units(A) ::= compilation_units(B) compilation_unit(C). { if (C) { C->next = B; A = C; } }
%type compilation_unit { CompilationUnit * }
%destructor compilation_unit { delete_compilation_unit(ctx, $$); }
compilation_unit(A) ::= variable_declaration(B). { A = new_global_variable(ctx, B); }
compilation_unit(A) ::= function_signature(B) SEMICOLON. { A = new_function(ctx, B, NULL); }
compilation_unit(A) ::= function_signature(B) statement_block(C). { A = new_function(ctx, B, C); }
compilation_unit(A) ::= typedef(B). { A = new_global_typedef(ctx, B); }
compilation_unit(A) ::= struct_declaration(B) SEMICOLON. { A = new_global_struct(ctx, B); }
//compilation_unit(A) ::= error SEMICOLON. { A = NULL; } // !!! FIXME: research using the error nonterminal
%type typedef { Typedef * }
%destructor typedef { delete_typedef(ctx, $$); }
// !!! FIXME: should CONST be here, or in datatype?
typedef(A) ::= TYPEDEF CONST datatype(B) scalar_or_array(C). { A = new_typedef(ctx, 1, B, C); }
typedef(A) ::= TYPEDEF datatype(B) scalar_or_array(C). { A = new_typedef(ctx, 0, B, C); }
%type function_signature { FunctionSignature * }
%destructor function_signature { delete_function_signature(ctx, $$); }
function_signature(A) ::= function_storageclass(B) function_details(C) semantic(D). { A = C; A->storage_class = B; A->semantic = D; }
function_signature(A) ::= function_storageclass(B) function_details(C). { A = C; A->storage_class = B; }
function_signature(A) ::= function_details(B) semantic(C). { A = B; A->semantic = C; }
function_signature(A) ::= function_details(B). { A = B; }
%type function_details { FunctionSignature * }
%destructor function_details { delete_function_signature(ctx, $$); }
function_details(A) ::= datatype(B) IDENTIFIER(C) LPAREN function_arguments(D) RPAREN. { A = new_function_signature(ctx, B, C.string, D); }
function_details(A) ::= VOID IDENTIFIER(B) LPAREN function_arguments(C) RPAREN. { A = new_function_signature(ctx, NULL, B.string, C); }
Mar 7, 2009
Mar 7, 2009
114
115
116
117
118
119
120
// !!! FIXME: there is a "target" storage class that is the name of the
// !!! FIXME: platform that this function is meant for...but I don't know
// !!! FIXME: what tokens are valid here.
// !!! FIXME: Also, the docs say "one of" inline or target, but I bet you can
// !!! FIXME: specify both.
Feb 19, 2010
Feb 19, 2010
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
%type function_storageclass { FunctionStorageClass }
//function_storageclass(A) ::= target(B). { A = B; }
function_storageclass(A) ::= INLINE. { A = FNSTORECLS_INLINE; }
%type function_arguments { FunctionArguments * }
%destructor function_arguments { delete_function_args(ctx, $$); }
function_arguments(A) ::= VOID. { A = NULL; }
function_arguments(A) ::= function_argument_list(B). { A = B; }
function_arguments(A) ::= . { A = NULL; }
%type function_argument_list { FunctionArguments * }
%destructor function_argument_list { delete_function_args(ctx, $$); }
function_argument_list(A) ::= function_argument(B). { A = B; }
function_argument_list(A) ::= function_argument_list(B) COMMA function_argument(C). { C->next = B; A = C; }
// !!! FIXME: this is pretty unreadable.
%type function_argument { FunctionArguments * }
%destructor function_argument { delete_function_args(ctx, $$); }
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E) interpolation_mod(F) initializer(G). { A = new_function_arg(ctx, B, C, D.string, E, F, G); }
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E) interpolation_mod(F). { A = new_function_arg(ctx, B, C, D.string, E, F, NULL); }
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E) initializer(F). { A = new_function_arg(ctx, B, C, D.string, E, INTERPMOD_NONE, F); }
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E). { A = new_function_arg(ctx, B, C, D.string, E, INTERPMOD_NONE, NULL); }
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) interpolation_mod(E) initializer(F). { A = new_function_arg(ctx, B, C, D.string, NULL, E, F); }
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) interpolation_mod(E). { A = new_function_arg(ctx, B, C, D.string, NULL, E, NULL); }
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) initializer(E). { A = new_function_arg(ctx, B, C, D.string, NULL, INTERPMOD_NONE, E); }
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D). { A = new_function_arg(ctx, B, C, D.string, NULL, INTERPMOD_NONE, NULL); }
function_argument(A) ::= datatype(B) IDENTIFIER(C) semantic(D) interpolation_mod(E) initializer(F). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, D, E, F); }
function_argument(A) ::= datatype(B) IDENTIFIER(C) semantic(D) interpolation_mod(E). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, D, E, NULL); }
function_argument(A) ::= datatype(B) IDENTIFIER(C) semantic(D) initializer(E). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, D, INTERPMOD_NONE, E); }
function_argument(A) ::= datatype(B) IDENTIFIER(C) semantic(D). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, D, INTERPMOD_NONE, NULL); }
function_argument(A) ::= datatype(B) IDENTIFIER(C) interpolation_mod(D) initializer(E). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, NULL, D, E); }
function_argument(A) ::= datatype(B) IDENTIFIER(C) interpolation_mod(D). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, NULL, D, NULL); }
function_argument(A) ::= datatype(B) IDENTIFIER(C) initializer(D). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, NULL, INTERPMOD_NONE, D); }
function_argument(A) ::= datatype(B) IDENTIFIER(C). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, NULL, INTERPMOD_NONE, NULL); }
%type input_modifier { InputModifier }
input_modifier(A) ::= IN. { A = INPUTMOD_IN; }
input_modifier(A) ::= INOUT. { A = INPUTMOD_INOUT; }
input_modifier(A) ::= OUT. { A = INPUTMOD_OUT; }
input_modifier(A) ::= IN OUT. { A = INPUTMOD_INOUT; }
input_modifier(A) ::= OUT IN. { A = INPUTMOD_INOUT; }
input_modifier(A) ::= UNIFORM. { A = INPUTMOD_UNIFORM; }
%type semantic { const char * }
Feb 21, 2010
Feb 21, 2010
165
semantic(A) ::= COLON IDENTIFIER(B). { A = B.string; }
Mar 7, 2009
Mar 7, 2009
166
167
// DX10 only?
Feb 19, 2010
Feb 19, 2010
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
%type interpolation_mod { InterpolationModifier }
interpolation_mod(A) ::= LINEAR. { A = INTERPMOD_LINEAR; }
interpolation_mod(A) ::= CENTROID. { A = INTERPMOD_CENTROID; }
interpolation_mod(A) ::= NOINTERPOLATION. { A = INTERPMOD_NOINTERPOLATION; }
interpolation_mod(A) ::= NOPERSPECTIVE. { A = INTERPMOD_NOPERSPECTIVE; }
interpolation_mod(A) ::= SAMPLE. { A = INTERPMOD_SAMPLE; }
%type variable_declaration { VariableDeclaration * }
%destructor variable_declaration { delete_variable_declaration(ctx, $$); }
variable_declaration(A) ::= variable_attribute_list(B) datatype(C) variable_declaration_details_list(D) SEMICOLON. { A = D; A->attributes = B; A->datatype = C; }
variable_declaration(A) ::= datatype(B) variable_declaration_details_list(C) SEMICOLON. { A = C; A->datatype = B; }
variable_declaration(A) ::= struct_declaration(B) variable_declaration_details_list(C) SEMICOLON. { A = C; A->anonymous_datatype = B; }
%type variable_attribute_list { int }
variable_attribute_list(A) ::= variable_attribute(B). { A = B; }
variable_attribute_list(A) ::= variable_attribute_list(B) variable_attribute(C). { A = B | C; }
%type variable_attribute { int }
variable_attribute(A) ::= EXTERN. { A = VARATTR_EXTERN; }
variable_attribute(A) ::= NOINTERPOLATION. { A = VARATTR_NOINTERPOLATION; }
variable_attribute(A) ::= SHARED. { A = VARATTR_SHARED; }
variable_attribute(A) ::= STATIC. { A = VARATTR_STATIC; }
variable_attribute(A) ::= UNIFORM. { A = VARATTR_UNIFORM; }
variable_attribute(A) ::= VOLATILE. { A = VARATTR_VOLATILE; }
variable_attribute(A) ::= CONST. { A = VARATTR_CONST; }
variable_attribute(A) ::= ROWMAJOR. { A = VARATTR_ROWMAJOR; }
variable_attribute(A) ::= COLUMNMAJOR. { A = VARATTR_COLUMNMAJOR; }
%type variable_declaration_details_list { VariableDeclaration * }
%destructor variable_declaration_details_list { delete_variable_declaration(ctx, $$); }
variable_declaration_details_list(A) ::= variable_declaration_details(B). { A = B; }
variable_declaration_details_list(A) ::= variable_declaration_details_list(B) COMMA variable_declaration_details(C). { A = C; A->next = B; }
%type variable_declaration_details { VariableDeclaration * }
%destructor variable_declaration_details { delete_variable_declaration(ctx, $$); }
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) annotations(D) initializer(E) variable_lowlevel(F). { A = new_variable_declaration(ctx, B, C, D, E, F); }
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) annotations(D) initializer(E). { A = new_variable_declaration(ctx, B, C, D, E, NULL); }
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) annotations(D) variable_lowlevel(E). { A = new_variable_declaration(ctx, B, C, D, NULL, E); }
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) annotations(D). { A = new_variable_declaration(ctx, B, C, D, NULL, NULL); }
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) initializer(D) variable_lowlevel(E). { A = new_variable_declaration(ctx, B, C, NULL, D, E); }
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) initializer(D). { A = new_variable_declaration(ctx, B, C, NULL, D, NULL); }
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) variable_lowlevel(D). { A = new_variable_declaration(ctx, B, C, NULL, NULL, D); }
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C). { A = new_variable_declaration(ctx, B, C, NULL, NULL, NULL); }
variable_declaration_details(A) ::= scalar_or_array(B) annotations(C) initializer(D) variable_lowlevel(E). { A = new_variable_declaration(ctx, B, NULL, C, D, E); }
variable_declaration_details(A) ::= scalar_or_array(B) annotations(C) initializer(D). { A = new_variable_declaration(ctx, B, NULL, C, D, NULL); }
variable_declaration_details(A) ::= scalar_or_array(B) annotations(C) variable_lowlevel(D). { A = new_variable_declaration(ctx, B, NULL, C, NULL, D); }
variable_declaration_details(A) ::= scalar_or_array(B) annotations(C). { A = new_variable_declaration(ctx, B, NULL, C, NULL, NULL); }
variable_declaration_details(A) ::= scalar_or_array(B) initializer(C) variable_lowlevel(D). { A = new_variable_declaration(ctx, B, NULL, NULL, C, D); }
variable_declaration_details(A) ::= scalar_or_array(B) initializer(C). { A = new_variable_declaration(ctx, B, NULL, NULL, C, NULL); }
variable_declaration_details(A) ::= scalar_or_array(B) variable_lowlevel(C). { A = new_variable_declaration(ctx, B, NULL, NULL, NULL, C); }
variable_declaration_details(A) ::= scalar_or_array(B). { A = new_variable_declaration(ctx, B, NULL, NULL, NULL, NULL); }
Mar 7, 2009
Mar 7, 2009
219
Mar 7, 2009
Mar 7, 2009
220
221
// !!! FIXME: we don't handle full sampler declarations at the moment.
Feb 19, 2010
Feb 19, 2010
222
223
224
225
%type struct_declaration { StructDeclaration * }
%destructor struct_declaration { delete_struct_declaration(ctx, $$); }
struct_declaration(A) ::= STRUCT IDENTIFIER(B) LBRACE struct_member_list(C) RBRACE.
Aug 23, 2009
Aug 23, 2009
226
{
Feb 19, 2010
Feb 19, 2010
227
228
229
A = new_struct_declaration(ctx, B.string, C);
// !!! FIXME: we need to decide what scope we are in and make sure this is only a valid usertype at that point.
add_usertype(ctx, B.string);
Aug 23, 2009
Aug 23, 2009
230
}
Mar 7, 2009
Mar 7, 2009
231
Feb 19, 2010
Feb 19, 2010
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
%type struct_member_list { StructMembers * }
%destructor struct_member_list { delete_struct_member(ctx, $$); }
struct_member_list(A) ::= struct_member(B). { A = B; }
struct_member_list(A) ::= struct_member_list(B) struct_member(C). { A = C; A->next = B; }
%type struct_member { StructMembers * }
%destructor struct_member { delete_struct_member(ctx, $$); }
struct_member(A) ::= interpolation_mod(B) struct_member_details(C). { StructMembers *i = C; A = C; while (i) { i->interpolation_mod = B; i = i->next; } }
struct_member(A) ::= struct_member_details(B). { A = B; }
%type struct_member_details { StructMembers * }
%destructor struct_member_details { delete_struct_member(ctx, $$); }
struct_member_details(A) ::= datatype(B) struct_member_item_list(C) SEMICOLON. { StructMembers *i = C; A = C; while (i) { i->datatype = B; i = i->next; } }
%type struct_member_item_list { StructMembers * }
%destructor struct_member_item_list { delete_struct_member(ctx, $$); }
struct_member_item_list(A) ::= scalar_or_array(B). { A = new_struct_member(ctx, B, NULL); }
struct_member_item_list(A) ::= scalar_or_array(B) semantic(C). { A = new_struct_member(ctx, B, C); }
struct_member_item_list(A) ::= struct_member_item_list(B) COMMA IDENTIFIER(C). { A = new_struct_member(ctx, new_scalar_or_array(ctx, C.string, 0, NULL), NULL); A->next = B; A->semantic = B->semantic; }
%type variable_lowlevel { VariableLowLevel * }
%destructor variable_lowlevel { delete_variable_lowlevel(ctx, $$); }
variable_lowlevel(A) ::= packoffset(B) register(C). { A = new_variable_lowlevel(ctx, B, C); }
variable_lowlevel(A) ::= register(B) packoffset(C). { A = new_variable_lowlevel(ctx, C, B); }
variable_lowlevel(A) ::= packoffset(B). { A = new_variable_lowlevel(ctx, B, NULL); }
variable_lowlevel(A) ::= register(B). { A = new_variable_lowlevel(ctx, NULL, B); }
// !!! FIXME: I sort of hate this type name.
%type scalar_or_array { ScalarOrArray * }
%destructor scalar_or_array { delete_scalar_or_array(ctx, $$); }
scalar_or_array(A) ::= IDENTIFIER(B) LBRACKET RBRACKET. { A = new_scalar_or_array(ctx, B.string, 1, NULL); }
scalar_or_array(A) ::= IDENTIFIER(B) LBRACKET expression(C) RBRACKET. { A = new_scalar_or_array(ctx, B.string, 1, C); }
scalar_or_array(A) ::= IDENTIFIER(B). { A = new_scalar_or_array(ctx, B.string, 0, NULL); }
%type packoffset { PackOffset * }
%destructor packoffset { delete_pack_offset(ctx, $$); }
packoffset(A) ::= COLON PACKOFFSET LPAREN IDENTIFIER(B) DOT IDENTIFIER(C) RPAREN. { A = new_pack_offset(ctx, B.string, C.string); }
packoffset(A) ::= COLON PACKOFFSET LPAREN IDENTIFIER(B) RPAREN. { A = new_pack_offset(ctx, B.string, NULL); }
// !!! FIXME: can take a profile, like ": register(ps_5_0, s)"
// !!! FIXME: IDENTIFIER is wrong: "s[2]" works, apparently. Use scalar_or_array instead?
// !!! FIXME: (these might be SM4 features)
%type register { const char * }
register(A) ::= COLON REGISTER LPAREN IDENTIFIER(B) RPAREN. { A = B.string; }
%type annotations { Annotations * }
%destructor annotations { delete_annotation(ctx, $$); }
annotations(A) ::= LT annotation_list(B) GT. { A = B; }
%type annotation_list { Annotations * }
%destructor annotation_list { delete_annotation(ctx, $$); }
annotation_list(A) ::= annotation(B). { A = B; }
annotation_list(A) ::= annotation_list(B) annotation(C). { A = C; A->next = B; }
// !!! FIXME: can this take a USERTYPE if we typedef'd a scalar type?
%type annotation { Annotations * }
%destructor annotation { delete_annotation(ctx, $$); }
annotation(A) ::= datatype_scalar(B) initializer(C) SEMICOLON. { A = new_annotation(ctx, B, C); }
%type initializer_block_list { Expression * }
%destructor initializer_block_list { delete_expr(ctx, $$); }
initializer_block_list(A) ::= expression(B). { A = B; }
initializer_block_list(A) ::= LBRACE initializer_block_list(B) RBRACE. { A = B; }
Feb 22, 2010
Feb 22, 2010
295
initializer_block_list(A) ::= initializer_block_list(B) COMMA initializer_block_list(C). { A = new_binary_expr(ctx, AST_OP_COMMA, B, C); }
Feb 19, 2010
Feb 19, 2010
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
%type initializer_block { Expression * }
%destructor initializer_block { delete_expr(ctx, $$); }
initializer_block(A) ::= LBRACE initializer_block_list(B) RBRACE. { A = B; }
%type initializer { Expression * }
%destructor initializer { delete_expr(ctx, $$); }
initializer(A) ::= ASSIGN initializer_block(B). { A = B; }
initializer(A) ::= ASSIGN expression(B). { A = B; }
%type intrinsic_datatype { const char * }
intrinsic_datatype(A) ::= datatype_vector(B). { A = B; }
intrinsic_datatype(A) ::= datatype_matrix(B). { A = B; }
intrinsic_datatype(A) ::= datatype_scalar(B). { A = B; }
intrinsic_datatype(A) ::= datatype_sampler(B). { A = B; }
%type datatype { const char * }
datatype(A) ::= intrinsic_datatype(B). { A = B; }
datatype(A) ::= USERTYPE(B). { A = B.string; }
%type datatype_sampler { const char * }
datatype_sampler(A) ::= SAMPLER. { A = cache_string_fmt(ctx, "s1"); }
datatype_sampler(A) ::= SAMPLER1D. { A = cache_string_fmt(ctx, "s1"); }
datatype_sampler(A) ::= SAMPLER2D. { A = cache_string_fmt(ctx, "s2"); }
datatype_sampler(A) ::= SAMPLER3D. { A = cache_string_fmt(ctx, "s3"); }
datatype_sampler(A) ::= SAMPLERCUBE. { A = cache_string_fmt(ctx, "sc"); }
datatype_sampler(A) ::= SAMPLER_STATE. { A = cache_string_fmt(ctx, "ss"); }
datatype_sampler(A) ::= SAMPLERSTATE. { A = cache_string_fmt(ctx, "ss"); }
datatype_sampler(A) ::= SAMPLERCOMPARISONSTATE. { A = cache_string_fmt(ctx, "sS"); }
%type datatype_scalar { const char * }
datatype_scalar(A) ::= BOOL. { A = cache_string_fmt(ctx, "b"); }
datatype_scalar(A) ::= INT. { A = cache_string_fmt(ctx, "i"); }
datatype_scalar(A) ::= UINT. { A = cache_string_fmt(ctx, "u"); }
datatype_scalar(A) ::= HALF. { A = cache_string_fmt(ctx, "h"); }
datatype_scalar(A) ::= FLOAT. { A = cache_string_fmt(ctx, "f"); }
datatype_scalar(A) ::= DOUBLE. { A = cache_string_fmt(ctx, "d"); }
datatype_scalar(A) ::= STRING. { A = cache_string_fmt(ctx, "S"); } // this is for the effects framework, not HLSL.
datatype_scalar(A) ::= SNORM FLOAT. { A = cache_string_fmt(ctx, "Fs"); }
datatype_scalar(A) ::= UNORM FLOAT. { A = cache_string_fmt(ctx, "Fu"); }
datatype_scalar(A) ::= BUFFER LT datatype_scalar(B) GT. { A = cache_string_fmt(ctx, "B%s", B); }
Mar 7, 2009
Mar 7, 2009
337
338
339
340
341
342
// !!! FIXME: MSDN suggests that the matrix ones are just typedefs inserted
// !!! FIXME: before parsing begins, like:
// !!! FIXME: typedef matrix <bool,4,3> bool4x3;
// !!! FIXME: ...maybe we can rip these out of the grammar and just create
// !!! FIXME: them at startup?
Feb 19, 2010
Feb 19, 2010
343
344
%type datatype_vector { const char * }
datatype_vector(A) ::= VECTOR LT datatype_scalar(B) COMMA INT_CONSTANT(C) GT. { A = cache_string_fmt(ctx, "v%d%s", (int) C.i64, B); }
Mar 7, 2009
Mar 7, 2009
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
datatype_vector ::= BOOL1.
datatype_vector ::= BOOL2.
datatype_vector ::= BOOL3.
datatype_vector ::= BOOL4.
datatype_vector ::= INT1.
datatype_vector ::= INT2.
datatype_vector ::= INT3.
datatype_vector ::= INT4.
datatype_vector ::= UINT1.
datatype_vector ::= UINT2.
datatype_vector ::= UINT3.
datatype_vector ::= UINT4.
datatype_vector ::= HALF1.
datatype_vector ::= HALF2.
datatype_vector ::= HALF3.
datatype_vector ::= HALF4.
datatype_vector ::= FLOAT1.
datatype_vector ::= FLOAT2.
datatype_vector ::= FLOAT3.
datatype_vector ::= FLOAT4.
datatype_vector ::= DOUBLE1.
datatype_vector ::= DOUBLE2.
datatype_vector ::= DOUBLE3.
datatype_vector ::= DOUBLE4.
Feb 19, 2010
Feb 19, 2010
370
371
%type datatype_matrix { const char * }
datatype_matrix(A) ::= MATRIX LT datatype_scalar(B) COMMA INT_CONSTANT(C) COMMA INT_CONSTANT(D) GT. { A = cache_string_fmt(ctx, "m%d%d%s", (int) C.i64, (int) D.i64, B); }
Mar 7, 2009
Mar 7, 2009
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
datatype_matrix ::= BOOL1X1.
datatype_matrix ::= BOOL1X2.
datatype_matrix ::= BOOL1X3.
datatype_matrix ::= BOOL1X4.
datatype_matrix ::= BOOL2X1.
datatype_matrix ::= BOOL2X2.
datatype_matrix ::= BOOL2X3.
datatype_matrix ::= BOOL2X4.
datatype_matrix ::= BOOL3X1.
datatype_matrix ::= BOOL3X2.
datatype_matrix ::= BOOL3X3.
datatype_matrix ::= BOOL3X4.
datatype_matrix ::= BOOL4X1.
datatype_matrix ::= BOOL4X2.
datatype_matrix ::= BOOL4X3.
datatype_matrix ::= BOOL4X4.
datatype_matrix ::= INT1X1.
datatype_matrix ::= INT1X2.
datatype_matrix ::= INT1X3.
datatype_matrix ::= INT1X4.
datatype_matrix ::= INT2X1.
datatype_matrix ::= INT2X2.
datatype_matrix ::= INT2X3.
datatype_matrix ::= INT2X4.
datatype_matrix ::= INT3X1.
datatype_matrix ::= INT3X2.
datatype_matrix ::= INT3X3.
datatype_matrix ::= INT3X4.
datatype_matrix ::= INT4X1.
datatype_matrix ::= INT4X2.
datatype_matrix ::= INT4X3.
datatype_matrix ::= INT4X4.
datatype_matrix ::= UINT1X1.
datatype_matrix ::= UINT1X2.
datatype_matrix ::= UINT1X3.
datatype_matrix ::= UINT1X4.
datatype_matrix ::= UINT2X1.
datatype_matrix ::= UINT2X2.
datatype_matrix ::= UINT2X3.
datatype_matrix ::= UINT2X4.
datatype_matrix ::= UINT3X1.
datatype_matrix ::= UINT3X2.
datatype_matrix ::= UINT3X3.
datatype_matrix ::= UINT3X4.
datatype_matrix ::= UINT4X1.
datatype_matrix ::= UINT4X2.
datatype_matrix ::= UINT4X3.
datatype_matrix ::= UINT4X4.
datatype_matrix ::= HALF1X1.
datatype_matrix ::= HALF1X2.
datatype_matrix ::= HALF1X3.
datatype_matrix ::= HALF1X4.
datatype_matrix ::= HALF2X1.
datatype_matrix ::= HALF2X2.
datatype_matrix ::= HALF2X3.
datatype_matrix ::= HALF2X4.
datatype_matrix ::= HALF3X1.
datatype_matrix ::= HALF3X2.
datatype_matrix ::= HALF3X3.
datatype_matrix ::= HALF3X4.
datatype_matrix ::= HALF4X1.
datatype_matrix ::= HALF4X2.
datatype_matrix ::= HALF4X3.
datatype_matrix ::= HALF4X4.
datatype_matrix ::= FLOAT1X1.
datatype_matrix ::= FLOAT1X2.
datatype_matrix ::= FLOAT1X3.
datatype_matrix ::= FLOAT1X4.
datatype_matrix ::= FLOAT2X1.
datatype_matrix ::= FLOAT2X2.
datatype_matrix ::= FLOAT2X3.
datatype_matrix ::= FLOAT2X4.
datatype_matrix ::= FLOAT3X1.
datatype_matrix ::= FLOAT3X2.
datatype_matrix ::= FLOAT3X3.
datatype_matrix ::= FLOAT3X4.
datatype_matrix ::= FLOAT4X1.
datatype_matrix ::= FLOAT4X2.
datatype_matrix ::= FLOAT4X3.
datatype_matrix ::= FLOAT4X4.
datatype_matrix ::= DOUBLE1X1.
datatype_matrix ::= DOUBLE1X2.
datatype_matrix ::= DOUBLE1X3.
datatype_matrix ::= DOUBLE1X4.
datatype_matrix ::= DOUBLE2X1.
datatype_matrix ::= DOUBLE2X2.
datatype_matrix ::= DOUBLE2X3.
datatype_matrix ::= DOUBLE2X4.
datatype_matrix ::= DOUBLE3X1.
datatype_matrix ::= DOUBLE3X2.
datatype_matrix ::= DOUBLE3X3.
datatype_matrix ::= DOUBLE3X4.
datatype_matrix ::= DOUBLE4X1.
datatype_matrix ::= DOUBLE4X2.
datatype_matrix ::= DOUBLE4X3.
datatype_matrix ::= DOUBLE4X4.
Feb 19, 2010
Feb 19, 2010
469
470
471
472
%type statement_block { Statement * }
%destructor statement_block { delete_statement(ctx, $$); }
statement_block(A) ::= LBRACE RBRACE. { A = new_empty_statement(ctx); }
statement_block(A) ::= LBRACE statement_list(B) RBRACE. { A = B; }
Feb 27, 2009
Feb 27, 2009
473
Feb 19, 2010
Feb 19, 2010
474
475
476
477
%type statement_list { Statement * }
%destructor statement_list { delete_statement(ctx, $$); }
statement_list(A) ::= statement(B). { A = B; }
statement_list(A) ::= statement_list(B) statement(C). { A = C; A->next = B; } // !!! FIXME: we're stacking this list backwards.
Mar 7, 2009
Mar 7, 2009
478
Aug 26, 2009
Aug 26, 2009
479
// These are for Shader Model 4 and Xbox 360 only, apparently.
Feb 19, 2010
Feb 19, 2010
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
// !!! FIXME: ...so we ignore them for now.
// !!! FIXME: can these stack? "[isolate][unused]{}" or something?
%type statement_attribute { int }
statement_attribute(A) ::= ISOLATE. { A = 0; } // !!! FIXME
statement_attribute(A) ::= MAXINSTRUCTIONCOUNT LPAREN INT_CONSTANT RPAREN. { A = 0; } // !!! FIXME
statement_attribute(A) ::= NOEXPRESSIONOPTIMIZATIONS. { A = 0; } // !!! FIXME
statement_attribute(A) ::= REMOVEUNUSEDINPUTS. { A = 0; } // !!! FIXME
statement_attribute(A) ::= UNUSED. { A = 0; } // !!! FIXME
statement_attribute(A) ::= XPS. { A = 0; } // !!! FIXME
%type statement { Statement * }
%destructor statement { delete_statement(ctx, $$); }
statement(A) ::= BREAK SEMICOLON. { A = new_break_statement(ctx); }
statement(A) ::= CONTINUE SEMICOLON. { A = new_continue_statement(ctx); }
statement(A) ::= DISCARD SEMICOLON. { A = new_discard_statement(ctx); }
statement(A) ::= LBRACKET statement_attribute(B) RBRACKET statement_block(C). { A = C; /* !!! FIXME: A->attributes = B;*/ B = 0; }
statement(A) ::= variable_declaration(B). { A = new_vardecl_statement(ctx, B); }
statement(A) ::= struct_declaration(B) SEMICOLON. { A = new_struct_statement(ctx, B); }
statement(A) ::= do_intro(B) DO statement(C) WHILE LPAREN expression(D) RPAREN SEMICOLON. { A = new_do_statement(ctx, B, C, D); }
statement(A) ::= while_intro(B) LPAREN expression(C) RPAREN statement(D). { A = new_while_statement(ctx, B, C, D); }
statement(A) ::= if_intro(B) LPAREN expression(C) RPAREN statement(D). { A = new_if_statement(ctx, B, C, D, NULL); }
statement(A) ::= if_intro(B) LPAREN expression(C) RPAREN statement(D) ELSE statement(E). { A = new_if_statement(ctx, B, C, D, E); }
statement(A) ::= switch_intro(B) LPAREN expression(C) RPAREN LBRACE switch_case_list(D) RBRACE. { A = new_switch_statement(ctx, B, C, D); }
statement(A) ::= typedef(B). { A = new_typedef_statement(ctx, B); }
statement(A) ::= SEMICOLON. { A = new_empty_statement(ctx); }
statement(A) ::= expression(B) SEMICOLON. { A = new_expr_statement(ctx, B); }
statement(A) ::= RETURN SEMICOLON. { A = new_return_statement(ctx, NULL); }
statement(A) ::= RETURN expression(B) SEMICOLON. { A = new_return_statement(ctx, B); }
statement(A) ::= statement_block(B). { A = B; }
statement(A) ::= for_statement(B). { A = B; }
//statement(A) ::= error SEMICOLON. { A = NULL; } // !!! FIXME: research using the error nonterminal
%type while_intro { int64 }
while_intro(A) ::= LBRACKET UNROLL LPAREN INT_CONSTANT(B) RPAREN RBRACKET WHILE. { A = (B.i64 < 0) ? 0 : B.i64; }
while_intro(A) ::= LBRACKET UNROLL RBRACKET WHILE. { A = -1; }
while_intro(A) ::= LBRACKET LOOP RBRACKET WHILE. { A = 0; }
while_intro(A) ::= WHILE. { A = -1; }
%type for_statement { Statement * }
%destructor for_statement { delete_statement(ctx, $$); }
for_statement(A) ::= for_intro(B) for_details(C). { A = C; ((ForStatement *) A)->unroll = B; }
%type for_intro { int64 }
for_intro(A) ::= LBRACKET UNROLL LPAREN INT_CONSTANT(B) RPAREN RBRACKET FOR. { A = (B.i64 < 0) ? 0 : B.i64; }
for_intro(A) ::= LBRACKET UNROLL RBRACKET FOR. { A = -1; }
for_intro(A) ::= LBRACKET LOOP RBRACKET FOR. { A = 0; }
for_intro(A) ::= FOR. { A = -1; }
%type for_details { Statement * }
%destructor for_details { delete_statement(ctx, $$); }
for_details(A) ::= LPAREN expression(B) SEMICOLON expression(C) SEMICOLON expression(D) RPAREN statement(E). { A = new_for_statement(ctx, NULL, B, C, D, E); }
for_details(A) ::= LPAREN SEMICOLON SEMICOLON RPAREN statement(B). { A = new_for_statement(ctx, NULL, NULL, NULL, NULL, B); }
for_details(A) ::= LPAREN SEMICOLON SEMICOLON expression(B) RPAREN statement(C). { A = new_for_statement(ctx, NULL, NULL, NULL, B, C); }
for_details(A) ::= LPAREN SEMICOLON expression(B) SEMICOLON RPAREN statement(C). { A = new_for_statement(ctx, NULL, NULL, B, NULL, C); }
for_details(A) ::= LPAREN SEMICOLON expression(B) SEMICOLON expression(C) RPAREN statement(D). { A = new_for_statement(ctx, NULL, NULL, B, C, D); }
for_details(A) ::= LPAREN expression(B) SEMICOLON SEMICOLON RPAREN statement(C). { A = new_for_statement(ctx, NULL, B, NULL, NULL, C); }
for_details(A) ::= LPAREN expression(B) SEMICOLON SEMICOLON expression(C) RPAREN statement(D). { A = new_for_statement(ctx, NULL, B, NULL, C, D); }
for_details(A) ::= LPAREN expression(B) SEMICOLON expression(C) SEMICOLON RPAREN statement(D). { A = new_for_statement(ctx, NULL, B, C, NULL, D); }
for_details(A) ::= LPAREN variable_declaration(B) expression(C) SEMICOLON expression(D) RPAREN statement(E). { A = new_for_statement(ctx, B, NULL, C, D, E); }
for_details(A) ::= LPAREN variable_declaration(B) SEMICOLON RPAREN statement(C). { A = new_for_statement(ctx, B, NULL, NULL, NULL, C); }
for_details(A) ::= LPAREN variable_declaration(B) SEMICOLON expression(C) RPAREN statement(D). { A = new_for_statement(ctx, B, NULL, C, NULL, D); }
for_details(A) ::= LPAREN variable_declaration(B) expression(C) SEMICOLON RPAREN statement(D). { A = new_for_statement(ctx, B, NULL, C, NULL, D); }
%type do_intro { int64 }
do_intro(A) ::= LBRACKET UNROLL LPAREN INT_CONSTANT(B) RPAREN RBRACKET DO. { A = (B.i64 < 0) ? 0 : (int) B.i64; }
do_intro(A) ::= LBRACKET UNROLL RBRACKET DO. { A = -1; }
do_intro(A) ::= LBRACKET LOOP RBRACKET DO. { A = 0; }
do_intro(A) ::= DO. { A = -1; }
%type if_intro { int }
if_intro(A) ::= LBRACKET BRANCH RBRACKET IF. { A = IFATTR_BRANCH; }
if_intro(A) ::= LBRACKET FLATTEN RBRACKET IF. { A = IFATTR_FLATTEN; }
if_intro(A) ::= LBRACKET IFALL RBRACKET IF. { A = IFATTR_IFALL; }
if_intro(A) ::= LBRACKET IFANY RBRACKET IF. { A = IFATTR_IFANY; }
if_intro(A) ::= LBRACKET PREDICATE RBRACKET IF. { A = IFATTR_PREDICATE; }
if_intro(A) ::= LBRACKET PREDICATEBLOCK RBRACKET IF. { A = IFATTR_PREDICATEBLOCK; }
if_intro(A) ::= IF. { A = IFATTR_NONE; }
%type switch_intro { int }
switch_intro(A) ::= LBRACKET FLATTEN RBRACKET SWITCH. { A = SWITCHATTR_FLATTEN; }
switch_intro(A) ::= LBRACKET BRANCH RBRACKET SWITCH. { A = SWITCHATTR_BRANCH; }
switch_intro(A) ::= LBRACKET FORCECASE RBRACKET SWITCH. { A = SWITCHATTR_FORCECASE; }
switch_intro(A) ::= LBRACKET CALL RBRACKET SWITCH. { A = SWITCHATTR_CALL; }
switch_intro(A) ::= SWITCH. { A = SWITCHATTR_NONE; }
%type switch_case_list { SwitchCases * }
%destructor switch_case_list { delete_switch_case(ctx, $$); }
switch_case_list(A) ::= switch_case(B). { A = B; }
switch_case_list(A) ::= switch_case_list(B) switch_case(C). { A = C; A->next = B; }
Mar 7, 2009
Mar 7, 2009
569
570
571
// You can do math here, apparently, as long as it produces an int constant.
// ...so "case 3+2:" works.
Feb 19, 2010
Feb 19, 2010
572
573
574
575
576
577
%type switch_case { SwitchCases * }
%destructor switch_case { delete_switch_case(ctx, $$); }
switch_case(A) ::= CASE expression(B) COLON statement_list(C). { A = new_switch_case(ctx, B, C); }
switch_case(A) ::= CASE expression(B) COLON. { A = new_switch_case(ctx, B, NULL); }
switch_case(A) ::= DEFAULT COLON statement_list(B). { A = new_switch_case(ctx, NULL, B); }
switch_case(A) ::= DEFAULT COLON. { A = new_switch_case(ctx, NULL, NULL); }
Mar 7, 2009
Mar 7, 2009
578
579
// the expression stuff is based on Jeff Lee's ANSI C grammar.
Feb 9, 2010
Feb 9, 2010
580
%type primary_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
581
%destructor primary_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
582
583
584
585
586
587
588
primary_expr(A) ::= IDENTIFIER(B). { A = new_identifier_expr(ctx, B.string); }
primary_expr(A) ::= INT_CONSTANT(B). { A = new_literal_int_expr(ctx, B.i64); }
primary_expr(A) ::= FLOAT_CONSTANT(B). { A = new_literal_float_expr(ctx, B.dbl); }
primary_expr(A) ::= STRING_LITERAL(B). { A = new_literal_string_expr(ctx, B.string); }
primary_expr(A) ::= LPAREN expression(B) RPAREN. { A = B; }
%type postfix_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
589
%destructor postfix_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
590
postfix_expr(A) ::= primary_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
591
592
593
postfix_expr(A) ::= postfix_expr(B) LBRACKET expression(C) RBRACKET. { A = new_binary_expr(ctx, AST_OP_DEREF_ARRAY, B, C); }
postfix_expr(A) ::= postfix_expr(B) LPAREN RPAREN. { A = new_binary_expr(ctx, AST_OP_CALLFUNC, B, NULL); }
postfix_expr(A) ::= postfix_expr(B) LPAREN argument_expr_list(C) RPAREN. { A = new_binary_expr(ctx, AST_OP_CALLFUNC, B, C); }
Feb 20, 2010
Feb 20, 2010
594
postfix_expr(A) ::= datatype(B) LPAREN argument_expr_list(C) RPAREN. { A = NULL; new_constructor_expr(ctx, B, C); } // HLSL constructor
Feb 22, 2010
Feb 22, 2010
595
596
597
postfix_expr(A) ::= postfix_expr(B) DOT IDENTIFIER(C). { A = new_binary_expr(ctx, AST_OP_DEREF_STRUCT, B, new_identifier_expr(ctx, C.string)); }
postfix_expr(A) ::= postfix_expr(B) PLUSPLUS. { A = new_unary_expr(ctx, AST_OP_POSTINCREMENT, B); }
postfix_expr(A) ::= postfix_expr(B) MINUSMINUS. { A = new_unary_expr(ctx, AST_OP_POSTDECREMENT, B); }
Feb 9, 2010
Feb 9, 2010
598
599
%type argument_expr_list { Expression * }
Feb 19, 2010
Feb 19, 2010
600
%destructor argument_expr_list { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
601
argument_expr_list(A) ::= assignment_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
602
argument_expr_list(A) ::= argument_expr_list(B) COMMA assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_COMMA, B, C); }
Feb 9, 2010
Feb 9, 2010
603
604
%type unary_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
605
606
%destructor unary_expr { delete_expr(ctx, $$); }
unary_expr(A) ::= postfix_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
607
608
unary_expr(A) ::= PLUSPLUS unary_expr(B). { A = new_unary_expr(ctx, AST_OP_PREINCREMENT, B); }
unary_expr(A) ::= MINUSMINUS unary_expr(B). { A = new_unary_expr(ctx, AST_OP_PREDECREMENT, B); }
Feb 9, 2010
Feb 9, 2010
609
unary_expr(A) ::= PLUS cast_expr(B). { A = B; } // unary "+x" is always a no-op, so throw it away here.
Feb 22, 2010
Feb 22, 2010
610
611
612
unary_expr(A) ::= MINUS cast_expr(B). { A = new_unary_expr(ctx, AST_OP_NEGATE, B); }
unary_expr(A) ::= COMPLEMENT cast_expr(B). { A = new_unary_expr(ctx, AST_OP_COMPLEMENT, B); }
unary_expr(A) ::= EXCLAMATION cast_expr(B). { A = new_unary_expr(ctx, AST_OP_NOT, B); }
Feb 9, 2010
Feb 9, 2010
613
614
%type cast_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
615
%destructor cast_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
616
cast_expr(A) ::= unary_expr(B). { A = B; }
Feb 20, 2010
Feb 20, 2010
617
cast_expr(A) ::= LPAREN datatype(B) RPAREN cast_expr(C). { A = new_cast_expr(ctx, B, C); }
Feb 9, 2010
Feb 9, 2010
618
619
%type multiplicative_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
620
%destructor multiplicative_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
621
multiplicative_expr(A) ::= cast_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
622
623
624
multiplicative_expr(A) ::= multiplicative_expr(B) STAR cast_expr(C). { A = new_binary_expr(ctx, AST_OP_MULTIPLY, B, C); }
multiplicative_expr(A) ::= multiplicative_expr(B) SLASH cast_expr(C). { A = new_binary_expr(ctx, AST_OP_DIVIDE, B, C); }
multiplicative_expr(A) ::= multiplicative_expr(B) PERCENT cast_expr(C). { A = new_binary_expr(ctx, AST_OP_MODULO, B, C); }
Feb 9, 2010
Feb 9, 2010
625
626
%type additive_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
627
%destructor additive_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
628
additive_expr(A) ::= multiplicative_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
629
630
additive_expr(A) ::= additive_expr(B) PLUS multiplicative_expr(C). { A = new_binary_expr(ctx, AST_OP_ADD, B, C); }
additive_expr(A) ::= additive_expr(B) MINUS multiplicative_expr(C). { A = new_binary_expr(ctx, AST_OP_SUBTRACT, B, C); }
Feb 9, 2010
Feb 9, 2010
631
632
%type shift_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
633
%destructor shift_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
634
shift_expr(A) ::= additive_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
635
636
shift_expr(A) ::= shift_expr(B) LSHIFT additive_expr(C). { A = new_binary_expr(ctx, AST_OP_LSHIFT, B, C); }
shift_expr(A) ::= shift_expr(B) RSHIFT additive_expr(C). { A = new_binary_expr(ctx, AST_OP_RSHIFT, B, C); }
Feb 9, 2010
Feb 9, 2010
637
638
%type relational_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
639
%destructor relational_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
640
relational_expr(A) ::= shift_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
641
642
643
644
relational_expr(A) ::= relational_expr(B) LT shift_expr(C). { A = new_binary_expr(ctx, AST_OP_LESSTHAN, B, C); }
relational_expr(A) ::= relational_expr(B) GT shift_expr(C). { A = new_binary_expr(ctx, AST_OP_GREATERTHAN, B, C); }
relational_expr(A) ::= relational_expr(B) LEQ shift_expr(C). { A = new_binary_expr(ctx, AST_OP_LESSTHANOREQUAL, B, C); }
relational_expr(A) ::= relational_expr(B) GEQ shift_expr(C). { A = new_binary_expr(ctx, AST_OP_GREATERTHANOREQUAL, B, C); }
Feb 9, 2010
Feb 9, 2010
645
646
%type equality_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
647
%destructor equality_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
648
equality_expr(A) ::= relational_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
649
650
equality_expr(A) ::= equality_expr(B) EQL relational_expr(C). { A = new_binary_expr(ctx, AST_OP_EQUAL, B, C); }
equality_expr(A) ::= equality_expr(B) NEQ relational_expr(C). { A = new_binary_expr(ctx, AST_OP_NOTEQUAL, B, C); }
Feb 9, 2010
Feb 9, 2010
651
652
%type and_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
653
%destructor and_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
654
and_expr(A) ::= equality_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
655
and_expr(A) ::= and_expr(B) AND equality_expr(C). { A = new_binary_expr(ctx, AST_OP_BINARYAND, B, C); }
Feb 9, 2010
Feb 9, 2010
656
657
%type exclusive_or_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
658
%destructor exclusive_or_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
659
exclusive_or_expr(A) ::= and_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
660
exclusive_or_expr(A) ::= exclusive_or_expr(B) XOR and_expr(C). { A = new_binary_expr(ctx, AST_OP_BINARYXOR, B, C); }
Feb 9, 2010
Feb 9, 2010
661
662
%type inclusive_or_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
663
%destructor inclusive_or_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
664
inclusive_or_expr(A) ::= exclusive_or_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
665
inclusive_or_expr(A) ::= inclusive_or_expr(B) OR exclusive_or_expr(C). { A = new_binary_expr(ctx, AST_OP_BINARYOR, B, C); }
Feb 9, 2010
Feb 9, 2010
666
667
%type logical_and_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
668
%destructor logical_and_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
669
logical_and_expr(A) ::= inclusive_or_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
670
logical_and_expr(A) ::= logical_and_expr(B) ANDAND inclusive_or_expr(C). { A = new_binary_expr(ctx, AST_OP_LOGICALAND, B, C); }
Feb 9, 2010
Feb 9, 2010
671
672
%type logical_or_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
673
%destructor logical_or_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
674
logical_or_expr(A) ::= logical_and_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
675
logical_or_expr(A) ::= logical_or_expr(B) OROR logical_and_expr(C). { A = new_binary_expr(ctx, AST_OP_LOGICALOR, B, C); }
Feb 9, 2010
Feb 9, 2010
676
677
%type conditional_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
678
%destructor conditional_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
679
conditional_expr(A) ::= logical_or_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
680
conditional_expr(A) ::= logical_or_expr(B) QUESTION logical_or_expr(C) COLON conditional_expr(D). { A = new_ternary_expr(ctx, AST_OP_CONDITIONAL, B, C, D); }
Feb 9, 2010
Feb 9, 2010
681
682
%type assignment_expr { Expression * }
Feb 19, 2010
Feb 19, 2010
683
%destructor assignment_expr { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
684
assignment_expr(A) ::= conditional_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
685
686
687
688
689
690
691
692
693
694
695
assignment_expr(A) ::= unary_expr(B) ASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_ASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) MULASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_MULASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) DIVASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_DIVASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) MODASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_MODASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) ADDASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_ADDASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) SUBASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_SUBASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) LSHIFTASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_LSHIFTASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) RSHIFTASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_RSHIFTASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) ANDASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_ANDASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) XORASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_XORASSIGN, B, C); }
assignment_expr(A) ::= unary_expr(B) ORASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_ORASSIGN, B, C); }
Feb 9, 2010
Feb 9, 2010
696
697
%type expression { Expression * }
Feb 19, 2010
Feb 19, 2010
698
%destructor expression { delete_expr(ctx, $$); }
Feb 9, 2010
Feb 9, 2010
699
expression(A) ::= assignment_expr(B). { A = B; }
Feb 22, 2010
Feb 22, 2010
700
expression(A) ::= expression(B) COMMA assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_COMMA, B, C); }
Feb 27, 2009
Feb 27, 2009
701
702
// end of mojoshader_parser_hlsl.lemon ...