source: trunk/test/sandbox/lex/lolfx.y @ 1413

Last change on this file since 1413 was 1413, checked in by sam, 9 years ago

test: more grammar improvements.

File size: 20.9 KB
Line 
1%{
2#include <cstdio>
3#include <iostream>
4
5extern "C" int yylex();
6extern "C" int yyparse();
7extern "C" FILE *yyin;
8extern "C" int yylineno;
9
10void yyerror(const char *s);
11%}
12
13/* The classic Bison union trick */
14%union
15{
16    int ival;
17    unsigned uval;
18    float fval;
19    char *sval;
20}
21
22%type <sval> lolfx_shader_name
23
24 /*
25  * GLSL and HLSL generic tokens
26  */
27
28%token <ival> BOOLCONSTANT
29%token <ival> INTCONSTANT
30%token <uval> UINTCONSTANT
31%token <fval> FLOATCONSTANT
32%token /* TODO */ FIELDSELECTION
33%token <sval> IDENTIFIER
34%token <sval> TYPENAME
35
36 /*
37  * GLSL keywords
38  * FIXME: unsorted
39  */
40
41%token GT_SUBROUTINE GT_PATCH GT_SAMPLE GT_FLAT GT_SMOOTH GT_LAYOUT
42%token GT_INVARIANT GT_HIGHP GT_MEDIUMP GT_LOWP GT_PRECISION
43
44 /*
45  * GLSL types
46  */
47
48%token GT_VEC2 GT_VEC3 GT_VEC4
49%token GT_BVEC2 GT_BVEC3 GT_BVEC4
50%token GT_DVEC2 GT_DVEC3 GT_DVEC4
51%token GT_IVEC2 GT_IVEC3 GT_IVEC4
52%token GT_UVEC2 GT_UVEC3 GT_UVEC4
53
54%token GT_MAT2 GT_MAT2X2 GT_MAT2X3 GT_MAT2X4
55%token GT_MAT3 GT_MAT3X2 GT_MAT3X3 GT_MAT3X4
56%token GT_MAT4 GT_MAT4X2 GT_MAT4X3 GT_MAT4X4
57%token GT_DMAT2 GT_DMAT2X2 GT_DMAT2X3 GT_DMAT2X4
58%token GT_DMAT3 GT_DMAT3X2 GT_DMAT3X3 GT_DMAT3X4
59%token GT_DMAT4 GT_DMAT4X2 GT_DMAT4X3 GT_DMAT4X4
60
61%token GT_SAMPLER1DSHADOW GT_SAMPLER1DARRAY GT_SAMPLER1DARRAYSHADOW
62%token GT_SAMPLER2DSHADOW GT_SAMPLER2DARRAY GT_SAMPLER2DARRAYSHADOW
63%token GT_SAMPLER2DRECT GT_SAMPLER2DRECTSHADOW
64%token GT_SAMPLER2DMS GT_SAMPLER2DMSARRAY
65%token GT_SAMPLERCUBESHADOW GT_SAMPLERCUBEARRAY GT_SAMPLERCUBEARRAYSHADOW
66%token GT_SAMPLERBUFFER
67
68%token GT_ISAMPLER1D GT_ISAMPLER1DARRAY
69%token GT_ISAMPLER2D GT_ISAMPLER2DARRAY
70%token GT_ISAMPLER2DRECT
71%token GT_ISAMPLER2DMS GT_ISAMPLER2DMSARRAY
72%token GT_ISAMPLER3D
73%token GT_ISAMPLERCUBE GT_ISAMPLERCUBEARRAY
74%token GT_ISAMPLERBUFFER
75
76%token GT_USAMPLER1D GT_USAMPLER1DARRAY
77%token GT_USAMPLER2D GT_USAMPLER2DARRAY
78%token GT_USAMPLER2DRECT
79%token GT_USAMPLER2DMS GT_USAMPLER2DMSARRAY
80%token GT_USAMPLER3D
81%token GT_USAMPLERCUBE GT_USAMPLERCUBEARRAY
82%token GT_USAMPLERBUFFER
83
84 /*
85  * HLSL and GLSL keywords
86  */
87
88%token GHT_BOOL GHT_BREAK GHT_CASE GHT_CENTROID GHT_CONST GHT_CONTINUE
89%token GHT_DEFAULT GHT_DISCARD GHT_DO GHT_DOUBLE GHT_ELSE GHT_FLOAT GHT_FOR
90%token GHT_IF GHT_IN GHT_INOUT GHT_INT GHT_NOPERSPECTIVE GHT_OUT GHT_RETURN
91%token GHT_SAMPLER1D GHT_SAMPLER2D GHT_SAMPLER3D GHT_SAMPLERCUBE GHT_STRUCT
92%token GHT_SWITCH GHT_UINT GHT_UNIFORM GHT_VOID GHT_WHILE
93
94%token HGT_BOOL HGT_BREAK HGT_CASE HGT_CENTROID HGT_CONST HGT_CONTINUE
95%token HGT_DEFAULT HGT_DISCARD HGT_DO HGT_DOUBLE HGT_ELSE HGT_FLOAT HGT_FOR
96%token HGT_IF HGT_IN HGT_INOUT HGT_INT HGT_NOPERSPECTIVE HGT_OUT HGT_RETURN
97%token HGT_SAMPLER1D HGT_SAMPLER2D HGT_SAMPLER3D HGT_SAMPLERCUBE HGT_STRUCT
98%token HGT_SWITCH HGT_UINT HGT_UNIFORM HGT_VOID HGT_WHILE
99
100 /*
101  * HLSL keywords
102  */
103
104%token HT_APPENDSTRUCTUREDBUFFER HT_ASM HT_ASM_FRAGMENT HT_BLENDSTATE
105%token HT_BUFFER HT_BYTEADDRESSBUFFER HT_CBUFFER
106%token HT_COLUMN_MAJOR HT_COMPILE HT_COMPILE_FRAGMENT HT_COMPILESHADER
107%token HT_COMPUTESHADER HT_CONSUMESTRUCTUREDBUFFER
108%token HT_DEPTHSTENCILSTATE HT_DEPTHSTENCILVIEW
109%token HT_DOMAINSHADER HT_DWORD HT_EXTERN HT_FALSE
110%token HT_FXGROUP HT_GEOMETRYSHADER HT_GROUPSHARED HT_HALF HT_HULLSHADER
111%token HT_INLINE HT_INPUTPATCH HT_INTERFACE HT_LINE
112%token HT_LINEADJ HT_LINEAR HT_LINESTREAM HT_MATRIX HT_NAMESPACE
113%token HT_NOINTERPOLATION HT_NULL HT_OUTPUTPATCH
114%token HT_PACKOFFSET HT_PASS HT_PIXELFRAGMENT HT_PIXELSHADER HT_POINT
115%token HT_POINTSTREAM HT_PRECISE HT_RASTERIZERSTATE HT_RENDERTARGETVIEW
116%token HT_REGISTER HT_ROW_MAJOR HT_RWBUFFER HT_RWBYTEADDRESSBUFFER
117%token HT_RWSTRUCTUREDBUFFER HT_RWTEXTURE1D HT_RWTEXTURE1DARRAY HT_RWTEXTURE2D
118%token HT_RWTEXTURE2DARRAY HT_RWTEXTURE3D HT_SAMPLER
119%token HT_SAMPLER_STATE HT_SAMPLERSTATE
120%token HT_SAMPLERCOMPARISONSTATE HT_SHARED HT_SNORM HT_STATEBLOCK
121%token HT_STATEBLOCK_STATE HT_STATIC HT_STRING
122%token HT_STRUCTUREDBUFFER HT_TBUFFER HT_TECHNIQUE HT_TECHNIQUE10
123%token HT_TECHNIQUE11XZ HT_TEXTURE HT_TEXTURE1D HT_TEXTURE1DARRAY HT_TEXTURE2D
124%token HT_TEXTURE2DARRAY HT_TEXTURE2DMS HT_TEXTURE2DMSARRAY HT_TEXTURE3D
125%token HT_TEXTURECUBE HT_TEXTURECUBEARRAY HT_TRUE HT_TYPEDEF HT_TRIANGLE
126%token HT_TRIANGLEADJ HT_TRIANGLESTREAM HT_UNORM HT_VECTOR
127%token HT_VERTEXFRAGMENT HT_VERTEXSHADER HT_VOLATILE
128
129 /*
130  * HLSL types
131  */
132
133%token HT_BOOL1 HT_BOOL1x1 HT_BOOL2x1 HT_BOOL3x1 HT_BOOL4x1
134%token HT_BOOL2 HT_BOOL1x2 HT_BOOL2x2 HT_BOOL3x2 HT_BOOL4x2
135%token HT_BOOL3 HT_BOOL1x3 HT_BOOL2x3 HT_BOOL3x3 HT_BOOL4x3
136%token HT_BOOL4 HT_BOOL1x4 HT_BOOL2x4 HT_BOOL3x4 HT_BOOL4x4
137
138%token HT_FLOAT1 HT_FLOAT1x1 HT_FLOAT2x1 HT_FLOAT3x1 HT_FLOAT4x1
139%token HT_FLOAT2 HT_FLOAT1x2 HT_FLOAT2x2 HT_FLOAT3x2 HT_FLOAT4x2
140%token HT_FLOAT3 HT_FLOAT1x3 HT_FLOAT2x3 HT_FLOAT3x3 HT_FLOAT4x3
141%token HT_FLOAT4 HT_FLOAT1x4 HT_FLOAT2x4 HT_FLOAT3x4 HT_FLOAT4x4
142
143%token HT_DOUBLE1 HT_DOUBLE1x1 HT_DOUBLE2x1 HT_DOUBLE3x1 HT_DOUBLE4x1
144%token HT_DOUBLE2 HT_DOUBLE1x2 HT_DOUBLE2x2 HT_DOUBLE3x2 HT_DOUBLE4x2
145%token HT_DOUBLE3 HT_DOUBLE1x3 HT_DOUBLE2x3 HT_DOUBLE3x3 HT_DOUBLE4x3
146%token HT_DOUBLE4 HT_DOUBLE1x4 HT_DOUBLE2x4 HT_DOUBLE3x4 HT_DOUBLE4x4
147
148%token HT_DWORD1 HT_DWORD1x1 HT_DWORD2x1 HT_DWORD3x1 HT_DWORD4x1
149%token HT_DWORD2 HT_DWORD1x2 HT_DWORD2x2 HT_DWORD3x2 HT_DWORD4x2
150%token HT_DWORD3 HT_DWORD1x3 HT_DWORD2x3 HT_DWORD3x3 HT_DWORD4x3
151%token HT_DWORD4 HT_DWORD1x4 HT_DWORD2x4 HT_DWORD3x4 HT_DWORD4x4
152
153%token HT_INT1 HT_INT1x1 HT_INT2x1 HT_INT3x1 HT_INT4x1
154%token HT_INT2 HT_INT1x2 HT_INT2x2 HT_INT3x2 HT_INT4x2
155%token HT_INT3 HT_INT1x3 HT_INT2x3 HT_INT3x3 HT_INT4x3
156%token HT_INT4 HT_INT1x4 HT_INT2x4 HT_INT3x4 HT_INT4x4
157
158%token HT_UINT1 HT_UINT1x1 HT_UINT2x1 HT_UINT3x1 HT_UINT4x1
159%token HT_UINT2 HT_UINT1x2 HT_UINT2x2 HT_UINT3x2 HT_UINT4x2
160%token HT_UINT3 HT_UINT1x3 HT_UINT2x3 HT_UINT3x3 HT_UINT4x3
161%token HT_UINT4 HT_UINT1x4 HT_UINT2x4 HT_UINT3x4 HT_UINT4x4
162
163 /*
164  * HLSL preprocessor directives
165  */
166
167%token PREPROCESSOR_DEFINE PREPROCESSOR_ELIF PREPROCESSOR_ELSE
168%token PREPROCESSOR_ENDIF PREPROCESSOR_ERROR PREPROCESSOR_IF
169%token PREPROCESSOR_IFDEF PREPROCESSOR_IFNDEF PREPROCESSOR_INCLUDE
170%token PREPROCESSOR_LINE PREPROCESSOR_PRAGMA PREPROCESSOR_UNDEF
171%token PREPROCESSOR_REGION
172
173 /*
174  * HLSL reserved keywords
175  */
176
177%token HT_AUTO HT_CATCH HT_CHAR HT_CLASS HT_CONST_CAST
178%token HT_DELETE HT_DYNAMIC_CAST HT_ENUM HT_EXPLICIT HT_FRIEND HT_GOTO HT_LONG
179%token HT_MUTABLE HT_NEW HT_OPERATOR HT_PRIVATE HT_PROTECTED HT_PUBLIC
180%token HT_REINTERPRET_CAST HT_SHORT HT_SIGNED HT_SIZEOF HT_STATIC_CAST
181%token HT_TEMPLATE HT_THIS HT_THROW HT_TRY HT_TYPENAME HT_UNION HT_UNSIGNED
182%token HT_USING HT_VIRTUAL
183
184 /*
185  * Language keywords
186  */
187
188%token T_INC T_DEC T_LE T_GE T_EQ T_NE T_LEFT T_RIGHT T_AND T_OR T_XOR
189%token T_MULEQ T_DIVEQ T_MODEQ T_ADDEQ T_SUBEQ T_LEFTEQ T_RIGHTEQ T_ANDEQ
190%token T_XOREQ T_OREQ
191
192 /*
193  * Temporary shit
194  */
195
196%token <ival> INT
197%token <fval> FLOAT
198%token <sval> STRING NAME
199
200%%
201
202lolfx_file:
203    lolfx_section_list
204    ;
205
206lolfx_section_list:
207    lolfx_section
208    | lolfx_section_list lolfx_section
209    ;
210
211lolfx_section:
212    lolfx_technique
213    | lolfx_shader
214    ;
215
216 /*
217  * Grammar for techniques
218  */
219
220lolfx_technique:
221    HT_TECHNIQUE NAME '{' pass_list '}' { std::cout << "New tech" << std::endl; }
222    ;
223
224 /*
225  * Grammar for passes
226  */
227
228pass_list:
229    pass
230    | pass_list pass
231    ;
232
233pass:
234    HT_PASS NAME '{' pass_stmt_list '}' { std::cout << "New pass" << std::endl; }
235    ;
236
237pass_stmt_list:
238    pass_stmt
239    | pass_stmt_list pass_stmt
240    ;
241
242pass_stmt:
243    ';'
244    | NAME '=' NAME ';'
245    | NAME '=' INT ';'
246    | NAME '[' INT ']' '=' NAME ';'
247    | NAME '[' INT ']' '=' INT ';'
248    ;
249
250 /*
251  * Grammar for shaders
252  */
253
254lolfx_shader:
255    lolfx_shader_region glsl_translation_unit
256    | lolfx_shader_region
257    ;
258
259lolfx_shader_region:
260    PREPROCESSOR_REGION lolfx_shader_name { std::cout << "new shader " << $2 << std::endl; }
261    ;
262
263lolfx_shader_name:
264    IDENTIFIER                            { $$ = $1; }
265    | lolfx_shader_name '.' IDENTIFIER    { $$ = $3; } /* FIXME: concatenate */
266    ;
267
268 /*
269  * Grammar for GLSL
270  */
271
272glsl_variable_identifier:
273    IDENTIFIER
274    ;
275
276glsl_primary_expression:
277    glsl_variable_identifier
278    | INTCONSTANT
279    | UINTCONSTANT
280    | FLOATCONSTANT
281    | BOOLCONSTANT
282    | '(' glsl_expression ')'
283    ;
284
285glsl_postfix_expression:
286    glsl_primary_expression
287    | glsl_postfix_expression '[' glsl_integer_expression ']'
288    | glsl_function_call
289    | glsl_postfix_expression '.' FIELDSELECTION
290    | glsl_postfix_expression T_INC
291    | glsl_postfix_expression T_DEC
292    ;
293
294glsl_integer_expression:
295    glsl_expression
296    ;
297
298glsl_function_call:
299    glsl_function_call_or_method
300    ;
301
302glsl_function_call_or_method:
303    glsl_function_call_generic
304    | glsl_postfix_expression '.' glsl_function_call_generic
305    ;
306
307glsl_function_call_generic:
308    glsl_function_call_header_with_parameters ')'
309    | glsl_function_call_header_no_parameters ')'
310    ;
311
312glsl_function_call_header_no_parameters:
313    glsl_function_call_header GHT_VOID
314    | glsl_function_call_header
315    ;
316
317glsl_function_call_header_with_parameters:
318    glsl_function_call_header glsl_assignment_expression
319    | glsl_function_call_header_with_parameters ',' glsl_assignment_expression
320    ;
321
322glsl_function_call_header:
323    glsl_function_identifier '('
324    ;
325
326glsl_function_identifier:
327    glsl_type_specifier
328    | IDENTIFIER
329    | FIELDSELECTION
330    ;
331
332glsl_unary_expression:
333    glsl_postfix_expression
334    | T_INC glsl_unary_expression
335    | T_DEC glsl_unary_expression
336    | glsl_unary_operator glsl_unary_expression
337    ;
338
339glsl_unary_operator:
340    '+'
341    | '-'
342    | '!'
343    | '~'
344    ;
345
346glsl_multiplicative_expression:
347    glsl_unary_expression
348    | glsl_multiplicative_expression '*' glsl_unary_expression
349    | glsl_multiplicative_expression '/' glsl_unary_expression
350    | glsl_multiplicative_expression '%' glsl_unary_expression
351    ;
352
353glsl_additive_expression:
354    glsl_multiplicative_expression
355    | glsl_additive_expression '+' glsl_multiplicative_expression
356    | glsl_additive_expression '-' glsl_multiplicative_expression
357    ;
358
359glsl_shift_expression:
360    glsl_additive_expression
361    | glsl_shift_expression T_LEFT glsl_additive_expression
362    | glsl_shift_expression T_RIGHT glsl_additive_expression
363    ;
364
365glsl_relational_expression:
366    glsl_shift_expression
367    | glsl_relational_expression '<' glsl_shift_expression
368    | glsl_relational_expression '>' glsl_shift_expression
369    | glsl_relational_expression T_LE glsl_shift_expression
370    | glsl_relational_expression T_GE glsl_shift_expression
371    ;
372
373glsl_equality_expression:
374    glsl_relational_expression
375    | glsl_equality_expression T_EQ glsl_relational_expression
376    | glsl_equality_expression T_NE glsl_relational_expression
377    ;
378
379glsl_and_expression:
380    glsl_equality_expression
381    | glsl_and_expression '&' glsl_equality_expression
382    ;
383
384glsl_exclusive_or_expression:
385    glsl_and_expression
386    | glsl_exclusive_or_expression '^' glsl_and_expression
387    ;
388
389glsl_inclusive_or_expression:
390    glsl_exclusive_or_expression
391    | glsl_inclusive_or_expression '|' glsl_exclusive_or_expression
392    ;
393
394glsl_logical_and_expression:
395    glsl_inclusive_or_expression
396    | glsl_logical_and_expression T_AND glsl_inclusive_or_expression
397    ;
398
399glsl_logical_xor_expression:
400    glsl_logical_and_expression
401    | glsl_logical_xor_expression T_XOR glsl_logical_and_expression
402    ;
403
404glsl_logical_or_expression:
405    glsl_logical_xor_expression
406    | glsl_logical_or_expression T_OR glsl_logical_xor_expression
407    ;
408
409glsl_conditional_expression:
410    glsl_logical_or_expression
411    | glsl_logical_or_expression '?' glsl_expression ':' glsl_assignment_expression
412    ;
413
414glsl_assignment_expression:
415    glsl_conditional_expression
416    | glsl_unary_expression glsl_assignment_operator glsl_assignment_expression
417    ;
418
419glsl_assignment_operator:
420    '='
421    | T_MULEQ
422    | T_DIVEQ
423    | T_MODEQ
424    | T_ADDEQ
425    | T_SUBEQ
426    | T_LEFTEQ
427    | T_RIGHTEQ
428    | T_ANDEQ
429    | T_XOREQ
430    | T_OREQ
431    ;
432
433glsl_expression:
434    glsl_assignment_expression
435    | glsl_expression ',' glsl_assignment_expression
436    ;
437
438glsl_constant_expression:
439    glsl_conditional_expression
440    ;
441
442glsl_declaration:
443    glsl_function_prototype ';'
444    | glsl_init_declarator_list ';'
445    | GT_PRECISION glsl_precision_qualifier glsl_type_specifier_no_prec ';'
446    | glsl_type_qualifier IDENTIFIER '{' glsl_struct_declaration_list '}' ';'
447    | glsl_type_qualifier IDENTIFIER '{' glsl_struct_declaration_list '}' IDENTIFIER ';'
448    | glsl_type_qualifier IDENTIFIER '{' glsl_struct_declaration_list '}' IDENTIFIER '[' ']' ';'
449    | glsl_type_qualifier IDENTIFIER '{' glsl_struct_declaration_list '}' IDENTIFIER '[' glsl_constant_expression ']' ';'
450    | glsl_type_qualifier ';'
451    ;
452
453glsl_function_prototype:
454    glsl_function_declarator ')'
455    ;
456
457glsl_function_declarator:
458    glsl_function_header
459    | glsl_function_header_with_parameters
460    ;
461
462glsl_function_header_with_parameters:
463    glsl_function_header glsl_parameter_declaration
464    | glsl_function_header_with_parameters ',' glsl_parameter_declaration
465    ;
466
467glsl_function_header:
468    glsl_fully_specified_type IDENTIFIER '('
469    ;
470
471glsl_parameter_declarator:
472    glsl_type_specifier IDENTIFIER
473    | glsl_type_specifier IDENTIFIER '[' glsl_constant_expression ']'
474    ;
475
476glsl_parameter_declaration:
477    glsl_parameter_type_qualifier glsl_parameter_qualifier glsl_parameter_declarator
478    | glsl_parameter_qualifier glsl_parameter_declarator
479    | glsl_parameter_type_qualifier glsl_parameter_qualifier glsl_parameter_type_specifier
480    | glsl_parameter_qualifier glsl_parameter_type_specifier
481    ;
482
483glsl_parameter_qualifier:
484    /* empty */
485    | GHT_IN
486    | GHT_OUT
487    | GHT_INOUT
488    ;
489
490glsl_parameter_type_specifier:
491    glsl_type_specifier
492    ;
493
494glsl_init_declarator_list:
495    glsl_single_declaration
496    | glsl_init_declarator_list ',' IDENTIFIER
497    | glsl_init_declarator_list ',' IDENTIFIER '[' ']'
498    | glsl_init_declarator_list ',' IDENTIFIER '[' glsl_constant_expression ']'
499    | glsl_init_declarator_list ',' IDENTIFIER '[' ']' '=' glsl_initializer
500    | glsl_init_declarator_list ',' IDENTIFIER '[' glsl_constant_expression ']' '=' glsl_initializer
501    | glsl_init_declarator_list ',' IDENTIFIER '=' glsl_initializer
502    ;
503
504glsl_single_declaration:
505    glsl_fully_specified_type
506    | glsl_fully_specified_type IDENTIFIER
507    | glsl_fully_specified_type IDENTIFIER '[' ']'
508    | glsl_fully_specified_type IDENTIFIER '[' glsl_constant_expression ']'
509    | glsl_fully_specified_type IDENTIFIER '[' ']' '=' glsl_initializer
510    | glsl_fully_specified_type IDENTIFIER '[' glsl_constant_expression ']' '=' glsl_initializer
511    | glsl_fully_specified_type IDENTIFIER '=' glsl_initializer
512    | GT_INVARIANT IDENTIFIER
513    ;
514
515glsl_fully_specified_type:
516    glsl_type_specifier
517    | glsl_type_qualifier glsl_type_specifier
518    ;
519
520glsl_invariant_qualifier:
521    GT_INVARIANT
522    ;
523
524glsl_interpolation_qualifier:
525    GT_SMOOTH
526    | GT_FLAT
527    | GHT_NOPERSPECTIVE
528    ;
529
530glsl_layout_qualifier:
531    GT_LAYOUT '(' glsl_layout_qualifier_id_list ')'
532    ;
533
534glsl_layout_qualifier_id_list:
535    glsl_layout_qualifier_id
536    | glsl_layout_qualifier_id_list ',' glsl_layout_qualifier_id
537    ;
538
539glsl_layout_qualifier_id:
540    IDENTIFIER
541    | IDENTIFIER '=' INTCONSTANT
542    ;
543
544glsl_parameter_type_qualifier:
545    GHT_CONST
546    ;
547
548glsl_type_qualifier:
549    glsl_storage_qualifier
550    | glsl_layout_qualifier
551    | glsl_layout_qualifier glsl_storage_qualifier
552    | glsl_interpolation_qualifier glsl_storage_qualifier
553    | glsl_interpolation_qualifier
554    | glsl_invariant_qualifier glsl_storage_qualifier
555    | glsl_invariant_qualifier glsl_interpolation_qualifier glsl_storage_qualifier
556    | glsl_invariant_qualifier
557    ;
558
559glsl_storage_qualifier:
560    GHT_CONST
561    | GHT_IN
562    | GHT_OUT
563    | GHT_CENTROID GHT_IN
564    | GHT_CENTROID GHT_OUT
565    | GT_PATCH GHT_IN
566    | GT_PATCH GHT_OUT
567    | GT_SAMPLE GHT_IN
568    | GT_SAMPLE GHT_OUT
569    | GHT_UNIFORM
570    ;
571
572glsl_type_specifier:
573    glsl_type_specifier_no_prec
574    | glsl_precision_qualifier glsl_type_specifier_no_prec
575    ;
576
577glsl_type_specifier_no_prec:
578    glsl_type_specifier_nonarray
579    | glsl_type_specifier_nonarray '[' ']'
580    | glsl_type_specifier_nonarray '[' glsl_constant_expression ']'
581
582glsl_type_specifier_nonarray:
583    GHT_VOID
584    | GHT_FLOAT
585    | GHT_DOUBLE
586    | GHT_INT
587    | GHT_UINT
588    | GHT_BOOL
589    | GT_VEC2
590    | GT_VEC3
591    | GT_VEC4
592    | GT_DVEC2
593    | GT_DVEC3
594    | GT_DVEC4
595    | GT_BVEC2
596    | GT_BVEC3
597    | GT_BVEC4
598    | GT_IVEC2
599    | GT_IVEC3
600    | GT_IVEC4
601    | GT_UVEC2
602    | GT_UVEC3
603    | GT_UVEC4
604    | GT_MAT2
605    | GT_MAT3
606    | GT_MAT4
607    | GT_MAT2X2
608    | GT_MAT2X3
609    | GT_MAT2X4
610    | GT_MAT3X2
611    | GT_MAT3X3
612    | GT_MAT3X4
613    | GT_MAT4X2
614    | GT_MAT4X3
615    | GT_MAT4X4
616    | GT_DMAT2
617    | GT_DMAT3
618    | GT_DMAT4
619    | GT_DMAT2X2
620    | GT_DMAT2X3
621    | GT_DMAT2X4
622    | GT_DMAT3X2
623    | GT_DMAT3X3
624    | GT_DMAT3X4
625    | GT_DMAT4X2
626    | GT_DMAT4X3
627    | GT_DMAT4X4
628    | GHT_SAMPLER1D
629    | GHT_SAMPLER2D
630    | GHT_SAMPLER3D
631    | GHT_SAMPLERCUBE
632    | GT_SAMPLER1DSHADOW
633    | GT_SAMPLER2DSHADOW
634    | GT_SAMPLERCUBESHADOW
635    | GT_SAMPLER1DARRAY
636    | GT_SAMPLER2DARRAY
637    | GT_SAMPLER1DARRAYSHADOW
638    | GT_SAMPLER2DARRAYSHADOW
639    | GT_SAMPLERCUBEARRAY
640    | GT_SAMPLERCUBEARRAYSHADOW
641    | GT_ISAMPLER1D
642    | GT_ISAMPLER2D
643    | GT_ISAMPLER3D
644    | GT_ISAMPLERCUBE
645    | GT_ISAMPLER1DARRAY
646    | GT_ISAMPLER2DARRAY
647    | GT_ISAMPLERCUBEARRAY
648    | GT_USAMPLER1D
649    | GT_USAMPLER2D
650    | GT_USAMPLER3D
651    | GT_USAMPLERCUBE
652    | GT_USAMPLER1DARRAY
653    | GT_USAMPLER2DARRAY
654    | GT_USAMPLERCUBEARRAY
655    | GT_SAMPLER2DRECT
656    | GT_SAMPLER2DRECTSHADOW
657    | GT_ISAMPLER2DRECT
658    | GT_USAMPLER2DRECT
659    | GT_SAMPLERBUFFER
660    | GT_ISAMPLERBUFFER
661    | GT_USAMPLERBUFFER
662    | GT_SAMPLER2DMS
663    | GT_ISAMPLER2DMS
664    | GT_USAMPLER2DMS
665    | GT_SAMPLER2DMSARRAY
666    | GT_ISAMPLER2DMSARRAY
667    | GT_USAMPLER2DMSARRAY
668    | glsl_struct_specifier
669    | TYPENAME
670    ;
671
672glsl_precision_qualifier:
673    GT_HIGHP
674    | GT_MEDIUMP
675    | GT_LOWP
676    ;
677
678glsl_struct_specifier:
679    GHT_STRUCT IDENTIFIER '{' glsl_struct_declaration_list '}'
680    | GHT_STRUCT '{' glsl_struct_declaration_list '}'
681    ;
682
683glsl_struct_declaration_list:
684    glsl_struct_declaration
685    | glsl_struct_declaration_list glsl_struct_declaration
686    ;
687
688glsl_struct_declaration:
689    glsl_type_specifier glsl_struct_declarator_list ';'
690    | glsl_type_qualifier glsl_type_specifier glsl_struct_declarator_list ';'
691    ;
692
693glsl_struct_declarator_list:
694    glsl_struct_declarator
695    | glsl_struct_declarator_list ',' glsl_struct_declarator
696    ;
697
698glsl_struct_declarator:
699    IDENTIFIER
700    | IDENTIFIER '[' ']'
701    | IDENTIFIER '[' glsl_constant_expression ']'
702    ;
703
704glsl_initializer:
705    glsl_assignment_expression
706    ;
707
708glsl_declaration_statement:
709    glsl_declaration
710    ;
711
712glsl_statement:
713    glsl_compound_statement
714    | glsl_simple_statement
715    ;
716
717glsl_simple_statement:
718    glsl_declaration_statement
719    | glsl_expression_statement
720    | glsl_selection_statement
721    | glsl_switch_statement
722    | glsl_case_label
723    | glsl_iteration_statement
724    | glsl_jump_statement
725    ;
726
727glsl_compound_statement:
728    '{' '}'
729    | '{' glsl_statement_list '}'
730    ;
731
732glsl_statement_no_new_scope:
733    glsl_compound_statement_no_new_scope
734    | glsl_simple_statement
735    ;
736
737glsl_compound_statement_no_new_scope:
738    '{' '}'
739    | '{' glsl_statement_list '}'
740    ;
741
742glsl_statement_list:
743    glsl_statement
744    | glsl_statement_list glsl_statement
745    ;
746
747glsl_expression_statement:
748    ';'
749    | glsl_expression ';'
750    ;
751
752glsl_selection_statement:
753    GHT_IF '(' glsl_expression ')' glsl_selection_rest_statement
754    ;
755
756glsl_selection_rest_statement:
757    glsl_statement GHT_ELSE glsl_statement
758    | glsl_statement
759    ;
760
761glsl_condition:
762    glsl_expression
763    | glsl_fully_specified_type IDENTIFIER '=' glsl_initializer
764    ;
765
766glsl_switch_statement:
767    GHT_SWITCH '(' glsl_expression ')' '{' glsl_switch_statement_list '}'
768    ;
769
770glsl_switch_statement_list:
771    /* nothing */
772    | glsl_statement_list
773    ;
774
775glsl_case_label:
776    GHT_CASE glsl_expression ':'
777    | GHT_DEFAULT ':'
778    ;
779
780glsl_iteration_statement:
781    GHT_WHILE '(' glsl_condition ')' glsl_statement_no_new_scope
782    | GHT_DO glsl_statement GHT_WHILE '(' glsl_expression ')' ';'
783    | GHT_FOR '(' glsl_for_init_statement glsl_for_rest_statement ')' glsl_statement_no_new_scope
784    ;
785
786glsl_for_init_statement:
787    glsl_expression_statement
788    | glsl_declaration_statement
789    ;
790
791glsl_conditionopt:
792    glsl_condition
793    | /* empty */
794    ;
795
796glsl_for_rest_statement:
797    glsl_conditionopt ';'
798    | glsl_conditionopt ';' glsl_expression
799    ;
800
801glsl_jump_statement:
802    GHT_CONTINUE ';'
803    | GHT_BREAK ';'
804    | GHT_RETURN ';'
805    | GHT_RETURN glsl_expression ';'
806    | GHT_DISCARD ';'
807    ;
808
809glsl_translation_unit:
810    glsl_external_declaration
811    | glsl_translation_unit glsl_external_declaration
812    ;
813
814glsl_external_declaration:
815    glsl_function_definition
816    | glsl_declaration
817    ;
818
819glsl_function_definition:
820    glsl_function_prototype glsl_compound_statement_no_new_scope
821    ;
822
823%%
824
825main()
826{
827    yyin = fopen("test.lolfx", "r");
828    do
829    {
830        yyparse();
831    }
832    while (!feof(yyin));
833
834    fclose(yyin);
835}
836
837void yyerror(const char *s)
838{
839    std::cout << "Parse error line " << yylineno << ": " << s << std::endl;
840    exit(-1);
841}
842
Note: See TracBrowser for help on using the repository browser.