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

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

test: add most of the GLSL grammar.

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