source: trunk/src/gpu/lolfx-parser.y @ 1937

Last change on this file since 1937 was 1937, checked in by sam, 7 years ago

lolfx: names such as "x" or "bgra" are field selectors, but we must also
accept them as variable names.

File size: 28.2 KB
Line 
1%{
2//
3// Lol Engine
4//
5// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
6//   This program is free software; you can redistribute it and/or
7//   modify it under the terms of the Do What The Fuck You Want To
8//   Public License, Version 2, as published by Sam Hocevar. See
9//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
10//
11
12#if defined HAVE_CONFIG_H
13#   include "config.h"
14#endif
15
16#include "core.h"
17
18#include <string>
19
20%}
21
22%require "2.3"
23%debug
24%defines
25%skeleton "lalr1.cc"
26%name-prefix="lol"
27%define parser_class_name "LolFxParser"
28%locations
29%parse-param { class LolFxCompiler& mc }
30%error-verbose
31
32/* The classic Bison union trick */
33%union
34{
35    int ival;
36    unsigned uval;
37    float fval;
38    char *sval;
39}
40
41/* %type <sval> lolfx_shader_name */
42
43 /*
44  * GLSL and HLSL generic tokens
45  */
46
47%token <ival> BOOLCONSTANT
48%token <ival> INTCONSTANT
49%token <uval> UINTCONSTANT
50%token <fval> FLOATCONSTANT
51%token <sval> FIELDSELECTION
52%token <sval> IDENTIFIER
53%token <sval> TYPENAME
54
55 /*
56  * GLSL keywords
57  * FIXME: unsorted
58  */
59
60%token GT_SUBROUTINE GT_PATCH GT_SAMPLE GT_FLAT GT_SMOOTH GT_LAYOUT
61%token GT_INVARIANT GT_HIGHP GT_MEDIUMP GT_LOWP GT_PRECISION
62
63 /*
64  * Deprecated GLSL keywords
65  */
66
67%token GT_ATTRIBUTE GT_VARYING
68
69 /*
70  * GLSL types
71  */
72
73%token GT_VEC2 GT_VEC3 GT_VEC4
74%token GT_BVEC2 GT_BVEC3 GT_BVEC4
75%token GT_DVEC2 GT_DVEC3 GT_DVEC4
76%token GT_IVEC2 GT_IVEC3 GT_IVEC4
77%token GT_UVEC2 GT_UVEC3 GT_UVEC4
78
79%token GT_MAT2 GT_MAT2X2 GT_MAT2X3 GT_MAT2X4
80%token GT_MAT3 GT_MAT3X2 GT_MAT3X3 GT_MAT3X4
81%token GT_MAT4 GT_MAT4X2 GT_MAT4X3 GT_MAT4X4
82%token GT_DMAT2 GT_DMAT2X2 GT_DMAT2X3 GT_DMAT2X4
83%token GT_DMAT3 GT_DMAT3X2 GT_DMAT3X3 GT_DMAT3X4
84%token GT_DMAT4 GT_DMAT4X2 GT_DMAT4X3 GT_DMAT4X4
85
86%token GT_SAMPLER1DSHADOW GT_SAMPLER1DARRAY GT_SAMPLER1DARRAYSHADOW
87%token GT_SAMPLER2DSHADOW GT_SAMPLER2DARRAY GT_SAMPLER2DARRAYSHADOW
88%token GT_SAMPLER2DRECT GT_SAMPLER2DRECTSHADOW
89%token GT_SAMPLER2DMS GT_SAMPLER2DMSARRAY
90%token GT_SAMPLERCUBESHADOW GT_SAMPLERCUBEARRAY GT_SAMPLERCUBEARRAYSHADOW
91%token GT_SAMPLERBUFFER
92
93%token GT_ISAMPLER1D GT_ISAMPLER1DARRAY
94%token GT_ISAMPLER2D GT_ISAMPLER2DARRAY
95%token GT_ISAMPLER2DRECT
96%token GT_ISAMPLER2DMS GT_ISAMPLER2DMSARRAY
97%token GT_ISAMPLER3D
98%token GT_ISAMPLERCUBE GT_ISAMPLERCUBEARRAY
99%token GT_ISAMPLERBUFFER
100
101%token GT_USAMPLER1D GT_USAMPLER1DARRAY
102%token GT_USAMPLER2D GT_USAMPLER2DARRAY
103%token GT_USAMPLER2DRECT
104%token GT_USAMPLER2DMS GT_USAMPLER2DMSARRAY
105%token GT_USAMPLER3D
106%token GT_USAMPLERCUBE GT_USAMPLERCUBEARRAY
107%token GT_USAMPLERBUFFER
108
109 /*
110  * GLSL keywords that are also in HLSL
111  */
112
113%token GHT_BOOL GHT_BREAK GHT_CASE GHT_CENTROID GHT_CONST GHT_CONTINUE
114%token GHT_DEFAULT GHT_DISCARD GHT_DO GHT_DOUBLE GHT_ELSE GHT_FLOAT GHT_FOR
115%token GHT_IF GHT_IN GHT_INOUT GHT_INT GHT_NOPERSPECTIVE GHT_OUT GHT_RETURN
116%token GHT_SAMPLER1D GHT_SAMPLER2D GHT_SAMPLER3D GHT_SAMPLERCUBE GHT_STRUCT
117%token GHT_SWITCH GHT_UINT GHT_UNIFORM GHT_VOID GHT_WHILE
118
119 /*
120  * HLSL keywords that are also in GLSL
121  */
122
123%token HGT_BOOL HGT_BREAK HGT_CASE HGT_CENTROID HGT_CONST HGT_CONTINUE
124%token HGT_DEFAULT HGT_DISCARD HGT_DO HGT_DOUBLE HGT_ELSE HGT_FLOAT HGT_FOR
125%token HGT_IF HGT_IN HGT_INOUT HGT_INT HGT_NOPERSPECTIVE HGT_OUT HGT_RETURN
126%token HGT_SAMPLER1D HGT_SAMPLER2D HGT_SAMPLER3D HGT_SAMPLERCUBE HGT_STRUCT
127%token HGT_SWITCH HGT_UINT HGT_UNIFORM HGT_VOID HGT_WHILE
128
129 /*
130  * HLSL keywords
131  */
132
133%token HT_APPENDSTRUCTUREDBUFFER HT_ASM HT_ASM_FRAGMENT HT_BLENDSTATE
134%token HT_BUFFER HT_BYTEADDRESSBUFFER HT_CBUFFER
135%token HT_COLUMN_MAJOR HT_COMPILE HT_COMPILE_FRAGMENT HT_COMPILESHADER
136%token HT_COMPUTESHADER HT_CONSUMESTRUCTUREDBUFFER
137%token HT_DEPTHSTENCILSTATE HT_DEPTHSTENCILVIEW
138%token HT_DOMAINSHADER HT_DWORD HT_EXTERN HT_FALSE
139%token HT_FXGROUP HT_GEOMETRYSHADER HT_GROUPSHARED HT_HALF HT_HULLSHADER
140%token HT_INLINE HT_INPUTPATCH HT_INTERFACE HT_LINE
141%token HT_LINEADJ HT_LINEAR HT_LINESTREAM HT_MATRIX HT_NAMESPACE
142%token HT_NOINTERPOLATION HT_NULL HT_OUTPUTPATCH
143%token HT_PACKOFFSET HT_PASS HT_PIXELFRAGMENT HT_PIXELSHADER HT_POINT
144%token HT_POINTSTREAM HT_PRECISE HT_RASTERIZERSTATE HT_RENDERTARGETVIEW
145%token HT_REGISTER HT_ROW_MAJOR HT_RWBUFFER HT_RWBYTEADDRESSBUFFER
146%token HT_RWSTRUCTUREDBUFFER HT_RWTEXTURE1D HT_RWTEXTURE1DARRAY HT_RWTEXTURE2D
147%token HT_RWTEXTURE2DARRAY HT_RWTEXTURE3D HT_SAMPLER
148%token HT_SAMPLER_STATE HT_SAMPLERSTATE
149%token HT_SAMPLERCOMPARISONSTATE HT_SHARED HT_SNORM HT_STATEBLOCK
150%token HT_STATEBLOCK_STATE HT_STATIC HT_STRING
151%token HT_STRUCTUREDBUFFER HT_TBUFFER HT_TECHNIQUE HT_TECHNIQUE10
152%token HT_TECHNIQUE11XZ HT_TEXTURE HT_TEXTURE1D HT_TEXTURE1DARRAY HT_TEXTURE2D
153%token HT_TEXTURE2DARRAY HT_TEXTURE2DMS HT_TEXTURE2DMSARRAY HT_TEXTURE3D
154%token HT_TEXTURECUBE HT_TEXTURECUBEARRAY HT_TRUE HT_TYPEDEF HT_TRIANGLE
155%token HT_TRIANGLEADJ HT_TRIANGLESTREAM HT_UNORM HT_VECTOR
156%token HT_VERTEXFRAGMENT HT_VERTEXSHADER HT_VOLATILE
157
158 /*
159  * HLSL types
160  */
161
162%token HT_BOOL1 HT_BOOL1x1 HT_BOOL2x1 HT_BOOL3x1 HT_BOOL4x1
163%token HT_BOOL2 HT_BOOL1x2 HT_BOOL2x2 HT_BOOL3x2 HT_BOOL4x2
164%token HT_BOOL3 HT_BOOL1x3 HT_BOOL2x3 HT_BOOL3x3 HT_BOOL4x3
165%token HT_BOOL4 HT_BOOL1x4 HT_BOOL2x4 HT_BOOL3x4 HT_BOOL4x4
166
167%token HT_FLOAT1 HT_FLOAT1x1 HT_FLOAT2x1 HT_FLOAT3x1 HT_FLOAT4x1
168%token HT_FLOAT2 HT_FLOAT1x2 HT_FLOAT2x2 HT_FLOAT3x2 HT_FLOAT4x2
169%token HT_FLOAT3 HT_FLOAT1x3 HT_FLOAT2x3 HT_FLOAT3x3 HT_FLOAT4x3
170%token HT_FLOAT4 HT_FLOAT1x4 HT_FLOAT2x4 HT_FLOAT3x4 HT_FLOAT4x4
171
172%token HT_DOUBLE1 HT_DOUBLE1x1 HT_DOUBLE2x1 HT_DOUBLE3x1 HT_DOUBLE4x1
173%token HT_DOUBLE2 HT_DOUBLE1x2 HT_DOUBLE2x2 HT_DOUBLE3x2 HT_DOUBLE4x2
174%token HT_DOUBLE3 HT_DOUBLE1x3 HT_DOUBLE2x3 HT_DOUBLE3x3 HT_DOUBLE4x3
175%token HT_DOUBLE4 HT_DOUBLE1x4 HT_DOUBLE2x4 HT_DOUBLE3x4 HT_DOUBLE4x4
176
177%token HT_DWORD1 HT_DWORD1x1 HT_DWORD2x1 HT_DWORD3x1 HT_DWORD4x1
178%token HT_DWORD2 HT_DWORD1x2 HT_DWORD2x2 HT_DWORD3x2 HT_DWORD4x2
179%token HT_DWORD3 HT_DWORD1x3 HT_DWORD2x3 HT_DWORD3x3 HT_DWORD4x3
180%token HT_DWORD4 HT_DWORD1x4 HT_DWORD2x4 HT_DWORD3x4 HT_DWORD4x4
181
182%token HT_INT1 HT_INT1x1 HT_INT2x1 HT_INT3x1 HT_INT4x1
183%token HT_INT2 HT_INT1x2 HT_INT2x2 HT_INT3x2 HT_INT4x2
184%token HT_INT3 HT_INT1x3 HT_INT2x3 HT_INT3x3 HT_INT4x3
185%token HT_INT4 HT_INT1x4 HT_INT2x4 HT_INT3x4 HT_INT4x4
186
187%token HT_UINT1 HT_UINT1x1 HT_UINT2x1 HT_UINT3x1 HT_UINT4x1
188%token HT_UINT2 HT_UINT1x2 HT_UINT2x2 HT_UINT3x2 HT_UINT4x2
189%token HT_UINT3 HT_UINT1x3 HT_UINT2x3 HT_UINT3x3 HT_UINT4x3
190%token HT_UINT4 HT_UINT1x4 HT_UINT2x4 HT_UINT3x4 HT_UINT4x4
191
192 /*
193  * HLSL preprocessor directives
194  */
195
196%token PREPROCESSOR_DEFINE PREPROCESSOR_ELIF PREPROCESSOR_ELSE
197%token PREPROCESSOR_ENDIF PREPROCESSOR_ERROR PREPROCESSOR_IF
198%token PREPROCESSOR_IFDEF PREPROCESSOR_IFNDEF PREPROCESSOR_INCLUDE
199%token PREPROCESSOR_LINE PREPROCESSOR_PRAGMA PREPROCESSOR_UNDEF
200%token PREPROCESSOR_REGION
201
202 /*
203  * HLSL reserved keywords
204  */
205
206%token HT_AUTO HT_CATCH HT_CHAR HT_CLASS HT_CONST_CAST
207%token HT_DELETE HT_DYNAMIC_CAST HT_ENUM HT_EXPLICIT HT_FRIEND HT_GOTO HT_LONG
208%token HT_MUTABLE HT_NEW HT_OPERATOR HT_PRIVATE HT_PROTECTED HT_PUBLIC
209%token HT_REINTERPRET_CAST HT_SHORT HT_SIGNED HT_SIZEOF HT_STATIC_CAST
210%token HT_TEMPLATE HT_THIS HT_THROW HT_TRY HT_TYPENAME HT_UNION HT_UNSIGNED
211%token HT_USING HT_VIRTUAL
212
213 /*
214  * Language symbols
215  */
216
217%token T_INC T_DEC T_LE T_GE T_EQ T_NE T_LEFT T_RIGHT T_AND T_OR T_XOR
218%token T_MULEQ T_DIVEQ T_MODEQ T_ADDEQ T_SUBEQ T_LEFTEQ T_RIGHTEQ T_ANDEQ
219%token T_XOREQ T_OREQ
220
221 /*
222  * Temporary shit
223  */
224
225%token <fval> FLOAT
226%token <sval> STRING NAME
227
228 /*
229  * Special tokens
230  */
231
232%token T_END 0
233%token T_ERROR
234
235 /*
236  * Our entry point
237  */
238
239%start lolfx_file
240
241%{
242#include "gpu/lolfx-compiler.h"
243
244#undef yylex
245#define yylex mc.m_lexer->lex
246%}
247
248%%
249
250 /*
251  * Shortcuts for token groups
252  */
253
254group_glsl_keyword:
255    GT_SUBROUTINE
256  | GT_PATCH
257  | GT_SAMPLE
258  | GT_FLAT
259  | GT_SMOOTH
260  | GT_LAYOUT
261  | GT_INVARIANT
262  | GT_HIGHP
263  | GT_MEDIUMP
264  | GT_LOWP
265  | GT_PRECISION
266  | GT_ATTRIBUTE /* deprecated */
267  | GT_VARYING /* deprecated */
268    ;
269
270group_glsl_type:
271    GT_VEC2
272  | GT_VEC3
273  | GT_VEC4
274  | GT_BVEC2
275  | GT_BVEC3
276  | GT_BVEC4
277  | GT_DVEC2
278  | GT_DVEC3
279  | GT_DVEC4
280  | GT_IVEC2
281  | GT_IVEC3
282  | GT_IVEC4
283  | GT_UVEC2
284  | GT_UVEC3
285  | GT_UVEC4
286  | GT_MAT2
287  | GT_MAT2X2
288  | GT_MAT2X3
289  | GT_MAT2X4
290  | GT_MAT3
291  | GT_MAT3X2
292  | GT_MAT3X3
293  | GT_MAT3X4
294  | GT_MAT4
295  | GT_MAT4X2
296  | GT_MAT4X3
297  | GT_MAT4X4
298  | GT_DMAT2
299  | GT_DMAT2X2
300  | GT_DMAT2X3
301  | GT_DMAT2X4
302  | GT_DMAT3
303  | GT_DMAT3X2
304  | GT_DMAT3X3
305  | GT_DMAT3X4
306  | GT_DMAT4
307  | GT_DMAT4X2
308  | GT_DMAT4X3
309  | GT_DMAT4X4
310  | GT_SAMPLER1DSHADOW
311  | GT_SAMPLER1DARRAY
312  | GT_SAMPLER1DARRAYSHADOW
313  | GT_SAMPLER2DSHADOW
314  | GT_SAMPLER2DARRAY
315  | GT_SAMPLER2DARRAYSHADOW
316  | GT_SAMPLER2DRECT
317  | GT_SAMPLER2DRECTSHADOW
318  | GT_SAMPLER2DMS
319  | GT_SAMPLER2DMSARRAY
320  | GT_SAMPLERCUBESHADOW
321  | GT_SAMPLERCUBEARRAY
322  | GT_SAMPLERCUBEARRAYSHADOW
323  | GT_SAMPLERBUFFER
324  | GT_ISAMPLER1D
325  | GT_ISAMPLER1DARRAY
326  | GT_ISAMPLER2D
327  | GT_ISAMPLER2DARRAY
328  | GT_ISAMPLER2DRECT
329  | GT_ISAMPLER2DMS
330  | GT_ISAMPLER2DMSARRAY
331  | GT_ISAMPLER3D
332  | GT_ISAMPLERCUBE
333  | GT_ISAMPLERCUBEARRAY
334  | GT_ISAMPLERBUFFER
335  | GT_USAMPLER1D
336  | GT_USAMPLER1DARRAY
337  | GT_USAMPLER2D
338  | GT_USAMPLER2DARRAY
339  | GT_USAMPLER2DRECT
340  | GT_USAMPLER2DMS
341  | GT_USAMPLER2DMSARRAY
342  | GT_USAMPLER3D
343  | GT_USAMPLERCUBE
344  | GT_USAMPLERCUBEARRAY
345  | GT_USAMPLERBUFFER
346    ;
347
348group_glsl_keyword_in_hlsl:
349    GHT_BOOL
350  | GHT_BREAK
351  | GHT_CASE
352  | GHT_CENTROID
353  | GHT_CONST
354  | GHT_CONTINUE
355  | GHT_DEFAULT
356  | GHT_DISCARD
357  | GHT_DO
358  | GHT_DOUBLE
359  | GHT_ELSE
360  | GHT_FLOAT
361  | GHT_FOR
362  | GHT_IF
363  | GHT_IN
364  | GHT_INOUT
365  | GHT_INT
366  | GHT_NOPERSPECTIVE
367  | GHT_OUT
368  | GHT_RETURN
369  | GHT_SAMPLER1D
370  | GHT_SAMPLER2D
371  | GHT_SAMPLER3D
372  | GHT_SAMPLERCUBE
373  | GHT_STRUCT
374  | GHT_SWITCH
375  | GHT_UINT
376  | GHT_UNIFORM
377  | GHT_VOID
378  | GHT_WHILE
379    ;
380
381group_hlsl_keyword_in_glsl:
382    HGT_BOOL
383  | HGT_BREAK
384  | HGT_CASE
385  | HGT_CENTROID
386  | HGT_CONST
387  | HGT_CONTINUE
388  | HGT_DEFAULT
389  | HGT_DISCARD
390  | HGT_DO
391  | HGT_DOUBLE
392  | HGT_ELSE
393  | HGT_FLOAT
394  | HGT_FOR
395  | HGT_IF
396  | HGT_IN
397  | HGT_INOUT
398  | HGT_INT
399  | HGT_NOPERSPECTIVE
400  | HGT_OUT
401  | HGT_RETURN
402  | HGT_SAMPLER1D
403  | HGT_SAMPLER2D
404  | HGT_SAMPLER3D
405  | HGT_SAMPLERCUBE
406  | HGT_STRUCT
407  | HGT_SWITCH
408  | HGT_UINT
409  | HGT_UNIFORM
410  | HGT_VOID
411  | HGT_WHILE
412    ;
413
414group_hlsl_keyword:
415    HT_APPENDSTRUCTUREDBUFFER
416  | HT_ASM
417  | HT_ASM_FRAGMENT
418  | HT_BLENDSTATE
419  | HT_BUFFER
420  | HT_BYTEADDRESSBUFFER
421  | HT_CBUFFER
422  | HT_COLUMN_MAJOR
423  | HT_COMPILE
424  | HT_COMPILE_FRAGMENT
425  | HT_COMPILESHADER
426  | HT_COMPUTESHADER
427  | HT_CONSUMESTRUCTUREDBUFFER
428  | HT_DEPTHSTENCILSTATE
429  | HT_DEPTHSTENCILVIEW
430  | HT_DOMAINSHADER
431  | HT_DWORD
432  | HT_EXTERN
433  | HT_FALSE
434  | HT_FXGROUP
435  | HT_GEOMETRYSHADER
436  | HT_GROUPSHARED
437  | HT_HALF
438  | HT_HULLSHADER
439  | HT_INLINE
440  | HT_INPUTPATCH
441  | HT_INTERFACE
442  | HT_LINE
443  | HT_LINEADJ
444  | HT_LINEAR
445  | HT_LINESTREAM
446  | HT_MATRIX
447  | HT_NAMESPACE
448  | HT_NOINTERPOLATION
449  | HT_NULL
450  | HT_OUTPUTPATCH
451  | HT_PACKOFFSET
452  | HT_PASS
453  | HT_PIXELFRAGMENT
454  | HT_PIXELSHADER
455  | HT_POINT
456  | HT_POINTSTREAM
457  | HT_PRECISE
458  | HT_RASTERIZERSTATE
459  | HT_RENDERTARGETVIEW
460  | HT_REGISTER
461  | HT_ROW_MAJOR
462  | HT_RWBUFFER
463  | HT_RWBYTEADDRESSBUFFER
464  | HT_RWSTRUCTUREDBUFFER
465  | HT_RWTEXTURE1D
466  | HT_RWTEXTURE1DARRAY
467  | HT_RWTEXTURE2D
468  | HT_RWTEXTURE2DARRAY
469  | HT_RWTEXTURE3D
470  | HT_SAMPLER
471  | HT_SAMPLER_STATE
472  | HT_SAMPLERSTATE
473  | HT_SAMPLERCOMPARISONSTATE
474  | HT_SHARED
475  | HT_SNORM
476  | HT_STATEBLOCK
477  | HT_STATEBLOCK_STATE
478  | HT_STATIC
479  | HT_STRING
480  | HT_STRUCTUREDBUFFER
481  | HT_TBUFFER
482  | HT_TECHNIQUE
483  | HT_TECHNIQUE10
484  | HT_TECHNIQUE11XZ
485  | HT_TEXTURE
486  | HT_TEXTURE1D
487  | HT_TEXTURE1DARRAY
488  | HT_TEXTURE2D
489  | HT_TEXTURE2DARRAY
490  | HT_TEXTURE2DMS
491  | HT_TEXTURE2DMSARRAY
492  | HT_TEXTURE3D
493  | HT_TEXTURECUBE
494  | HT_TEXTURECUBEARRAY
495  | HT_TRUE
496  | HT_TYPEDEF
497  | HT_TRIANGLE
498  | HT_TRIANGLEADJ
499  | HT_TRIANGLESTREAM
500  | HT_UNORM
501  | HT_VECTOR
502  | HT_VERTEXFRAGMENT
503  | HT_VERTEXSHADER
504  | HT_VOLATILE
505    ;
506
507group_hlsl_type:
508    HT_BOOL1
509  | HT_BOOL1x1
510  | HT_BOOL2x1
511  | HT_BOOL3x1
512  | HT_BOOL4x1
513  | HT_BOOL2
514  | HT_BOOL1x2
515  | HT_BOOL2x2
516  | HT_BOOL3x2
517  | HT_BOOL4x2
518  | HT_BOOL3
519  | HT_BOOL1x3
520  | HT_BOOL2x3
521  | HT_BOOL3x3
522  | HT_BOOL4x3
523  | HT_BOOL4
524  | HT_BOOL1x4
525  | HT_BOOL2x4
526  | HT_BOOL3x4
527  | HT_BOOL4x4
528  | HT_FLOAT1
529  | HT_FLOAT1x1
530  | HT_FLOAT2x1
531  | HT_FLOAT3x1
532  | HT_FLOAT4x1
533  | HT_FLOAT2
534  | HT_FLOAT1x2
535  | HT_FLOAT2x2
536  | HT_FLOAT3x2
537  | HT_FLOAT4x2
538  | HT_FLOAT3
539  | HT_FLOAT1x3
540  | HT_FLOAT2x3
541  | HT_FLOAT3x3
542  | HT_FLOAT4x3
543  | HT_FLOAT4
544  | HT_FLOAT1x4
545  | HT_FLOAT2x4
546  | HT_FLOAT3x4
547  | HT_FLOAT4x4
548  | HT_DOUBLE1
549  | HT_DOUBLE1x1
550  | HT_DOUBLE2x1
551  | HT_DOUBLE3x1
552  | HT_DOUBLE4x1
553  | HT_DOUBLE2
554  | HT_DOUBLE1x2
555  | HT_DOUBLE2x2
556  | HT_DOUBLE3x2
557  | HT_DOUBLE4x2
558  | HT_DOUBLE3
559  | HT_DOUBLE1x3
560  | HT_DOUBLE2x3
561  | HT_DOUBLE3x3
562  | HT_DOUBLE4x3
563  | HT_DOUBLE4
564  | HT_DOUBLE1x4
565  | HT_DOUBLE2x4
566  | HT_DOUBLE3x4
567  | HT_DOUBLE4x4
568  | HT_DWORD1
569  | HT_DWORD1x1
570  | HT_DWORD2x1
571  | HT_DWORD3x1
572  | HT_DWORD4x1
573  | HT_DWORD2
574  | HT_DWORD1x2
575  | HT_DWORD2x2
576  | HT_DWORD3x2
577  | HT_DWORD4x2
578  | HT_DWORD3
579  | HT_DWORD1x3
580  | HT_DWORD2x3
581  | HT_DWORD3x3
582  | HT_DWORD4x3
583  | HT_DWORD4
584  | HT_DWORD1x4
585  | HT_DWORD2x4
586  | HT_DWORD3x4
587  | HT_DWORD4x4
588  | HT_INT1
589  | HT_INT1x1
590  | HT_INT2x1
591  | HT_INT3x1
592  | HT_INT4x1
593  | HT_INT2
594  | HT_INT1x2
595  | HT_INT2x2
596  | HT_INT3x2
597  | HT_INT4x2
598  | HT_INT3
599  | HT_INT1x3
600  | HT_INT2x3
601  | HT_INT3x3
602  | HT_INT4x3
603  | HT_INT4
604  | HT_INT1x4
605  | HT_INT2x4
606  | HT_INT3x4
607  | HT_INT4x4
608  | HT_UINT1
609  | HT_UINT1x1
610  | HT_UINT2x1
611  | HT_UINT3x1
612  | HT_UINT4x1
613  | HT_UINT2
614  | HT_UINT1x2
615  | HT_UINT2x2
616  | HT_UINT3x2
617  | HT_UINT4x2
618  | HT_UINT3
619  | HT_UINT1x3
620  | HT_UINT2x3
621  | HT_UINT3x3
622  | HT_UINT4x3
623  | HT_UINT4
624  | HT_UINT1x4
625  | HT_UINT2x4
626  | HT_UINT3x4
627  | HT_UINT4x4
628    ;
629
630group_hlsl_preprocessor:
631    PREPROCESSOR_DEFINE
632  | PREPROCESSOR_ELIF
633  | PREPROCESSOR_ELSE
634  | PREPROCESSOR_ENDIF
635  | PREPROCESSOR_ERROR
636  | PREPROCESSOR_IF
637  | PREPROCESSOR_IFDEF
638  | PREPROCESSOR_IFNDEF
639  | PREPROCESSOR_INCLUDE
640  | PREPROCESSOR_LINE
641  | PREPROCESSOR_PRAGMA
642  | PREPROCESSOR_UNDEF
643  | PREPROCESSOR_REGION
644    ;
645
646group_hlsl_reserved:
647    HT_AUTO
648  | HT_CATCH
649  | HT_CHAR
650  | HT_CLASS
651  | HT_CONST_CAST
652  | HT_DELETE
653  | HT_DYNAMIC_CAST
654  | HT_ENUM
655  | HT_EXPLICIT
656  | HT_FRIEND
657  | HT_GOTO
658  | HT_LONG
659  | HT_MUTABLE
660  | HT_NEW
661  | HT_OPERATOR
662  | HT_PRIVATE
663  | HT_PROTECTED
664  | HT_PUBLIC
665  | HT_REINTERPRET_CAST
666  | HT_SHORT
667  | HT_SIGNED
668  | HT_SIZEOF
669  | HT_STATIC_CAST
670  | HT_TEMPLATE
671  | HT_THIS
672  | HT_THROW
673  | HT_TRY
674  | HT_TYPENAME
675  | HT_UNION
676  | HT_UNSIGNED
677  | HT_USING
678  | HT_VIRTUAL
679    ;
680
681group_language_symbols:
682    T_INC
683  | T_DEC
684  | T_LE
685  | T_GE
686  | T_EQ
687  | T_NE
688  | T_LEFT
689  | T_RIGHT
690  | T_AND
691  | T_OR
692  | T_XOR
693  | T_MULEQ
694  | T_DIVEQ
695  | T_MODEQ
696  | T_ADDEQ
697  | T_SUBEQ
698  | T_LEFTEQ
699  | T_RIGHTEQ
700  | T_ANDEQ
701  | T_XOREQ
702  | T_OREQ
703    ;
704
705 /*
706  * Grammar for LolFx files
707  */
708
709lolfx_file:
710    lolfx_section_list
711    ;
712
713lolfx_section_list:
714    lolfx_section
715  | lolfx_section lolfx_section_list
716    ;
717
718lolfx_section:
719    lolfx_technique
720  | lolfx_shader
721    ;
722
723 /*
724  * Grammar for techniques
725  */
726
727lolfx_technique:
728    HT_TECHNIQUE lolfx_identifier '{' pass_list '}' { std::cout << "New tech " << std::endl; }
729    ;
730
731 /*
732  * The valid LolFx identifiers
733  */
734
735lolfx_identifier:
736    IDENTIFIER     { std::cout << "New name " << $1 << std::endl; }
737  | FIELDSELECTION { std::cout << "New name " << $1 << std::endl; }
738    ;
739
740 /*
741  * Grammar for passes
742  */
743
744pass_list:
745    pass
746  | pass pass_list
747    ;
748
749pass:
750    HT_PASS lolfx_identifier '{' pass_stmt_list '}' { std::cout << "New pass " << std::endl; }
751    ;
752
753pass_stmt_list:
754    pass_stmt
755  | pass_stmt pass_stmt_list
756    ;
757
758 /* Shitty shit */
759pass_stmt:
760    ';'
761  | IDENTIFIER '=' IDENTIFIER ';'
762  | IDENTIFIER '=' INTCONSTANT ';'
763  | IDENTIFIER '=' BOOLCONSTANT ';'
764  | IDENTIFIER '=' HT_FALSE ';'
765  | IDENTIFIER '=' HT_TRUE ';'
766  | IDENTIFIER '[' INTCONSTANT ']' '=' IDENTIFIER ';'
767  | IDENTIFIER '[' INTCONSTANT ']' '=' INTCONSTANT ';'
768  | HT_TEXTURE '[' INTCONSTANT ']' '=' IDENTIFIER ';'
769  | HT_TEXTURE '[' INTCONSTANT ']' '=' HT_NULL ';'
770  | HT_DOMAINSHADER '=' IDENTIFIER ';'
771  | HT_GEOMETRYSHADER '=' IDENTIFIER ';'
772  | HT_HULLSHADER '=' IDENTIFIER ';'
773  | HT_PIXELSHADER '=' IDENTIFIER ';'
774  | HT_VERTEXSHADER '=' IDENTIFIER ';'
775    ;
776
777 /*
778  * Grammar for shaders
779  */
780
781lolfx_shader:
782    lolfx_shader_declaration glsl_translation_unit
783    ;
784
785lolfx_shader_declaration:
786    '[' lolfx_shader_name_list ']' { std::cout << "new shader" << std::endl; }
787    ;
788
789lolfx_shader_name_list:
790    lolfx_shader_name '.' lolfx_shader_name_list
791  | lolfx_shader_name
792    ;
793
794lolfx_shader_name:
795    lolfx_identifier
796    ;
797
798 /*
799  * Grammar for GLSL
800  */
801
802glsl_variable_identifier:
803    lolfx_identifier
804    ;
805
806glsl_primary_expression:
807    glsl_variable_identifier
808  | INTCONSTANT
809  | UINTCONSTANT
810  | FLOATCONSTANT
811  | BOOLCONSTANT
812  | '(' glsl_expression ')'
813    ;
814
815glsl_postfix_expression:
816    glsl_primary_expression
817  | glsl_postfix_expression '[' glsl_integer_expression ']'
818  | glsl_function_call
819  | glsl_postfix_expression '.' FIELDSELECTION
820  | glsl_postfix_expression T_INC
821  | glsl_postfix_expression T_DEC
822    ;
823
824glsl_integer_expression:
825    glsl_expression
826    ;
827
828glsl_function_call:
829    glsl_function_call_or_method
830    ;
831
832glsl_function_call_or_method:
833    glsl_function_call_generic
834  | glsl_postfix_expression '.' glsl_function_call_generic
835    ;
836
837glsl_function_call_generic:
838    glsl_function_call_header_with_parameters ')'
839  | glsl_function_call_header_no_parameters ')'
840    ;
841
842glsl_function_call_header_no_parameters:
843    glsl_function_call_header GHT_VOID
844  | glsl_function_call_header
845    ;
846
847glsl_function_call_header_with_parameters:
848    glsl_function_call_header glsl_assignment_expression
849  | glsl_function_call_header_with_parameters ',' glsl_assignment_expression
850    ;
851
852glsl_function_call_header:
853    glsl_function_identifier '('
854    ;
855
856glsl_function_identifier:
857    glsl_type_specifier
858  | IDENTIFIER
859  | FIELDSELECTION
860    ;
861
862glsl_unary_expression:
863    glsl_postfix_expression
864  | T_INC glsl_unary_expression
865  | T_DEC glsl_unary_expression
866  | glsl_unary_operator glsl_unary_expression
867    ;
868
869glsl_unary_operator:
870    '+'
871  | '-'
872  | '!'
873  | '~'
874    ;
875
876glsl_multiplicative_expression:
877    glsl_unary_expression
878  | glsl_multiplicative_expression '*' glsl_unary_expression
879  | glsl_multiplicative_expression '/' glsl_unary_expression
880  | glsl_multiplicative_expression '%' glsl_unary_expression
881    ;
882
883glsl_additive_expression:
884    glsl_multiplicative_expression
885  | glsl_additive_expression '+' glsl_multiplicative_expression
886  | glsl_additive_expression '-' glsl_multiplicative_expression
887    ;
888
889glsl_shift_expression:
890    glsl_additive_expression
891  | glsl_shift_expression T_LEFT glsl_additive_expression
892  | glsl_shift_expression T_RIGHT glsl_additive_expression
893    ;
894
895glsl_relational_expression:
896    glsl_shift_expression
897  | glsl_relational_expression '<' glsl_shift_expression
898  | glsl_relational_expression '>' glsl_shift_expression
899  | glsl_relational_expression T_LE glsl_shift_expression
900  | glsl_relational_expression T_GE glsl_shift_expression
901    ;
902
903glsl_equality_expression:
904    glsl_relational_expression
905  | glsl_equality_expression T_EQ glsl_relational_expression
906  | glsl_equality_expression T_NE glsl_relational_expression
907    ;
908
909glsl_and_expression:
910    glsl_equality_expression
911  | glsl_and_expression '&' glsl_equality_expression
912    ;
913
914glsl_exclusive_or_expression:
915    glsl_and_expression
916  | glsl_exclusive_or_expression '^' glsl_and_expression
917    ;
918
919glsl_inclusive_or_expression:
920    glsl_exclusive_or_expression
921  | glsl_inclusive_or_expression '|' glsl_exclusive_or_expression
922    ;
923
924glsl_logical_and_expression:
925    glsl_inclusive_or_expression
926  | glsl_logical_and_expression T_AND glsl_inclusive_or_expression
927    ;
928
929glsl_logical_xor_expression:
930    glsl_logical_and_expression
931  | glsl_logical_xor_expression T_XOR glsl_logical_and_expression
932    ;
933
934glsl_logical_or_expression:
935    glsl_logical_xor_expression
936  | glsl_logical_or_expression T_OR glsl_logical_xor_expression
937    ;
938
939glsl_conditional_expression:
940    glsl_logical_or_expression
941  | glsl_logical_or_expression '?' glsl_expression ':' glsl_assignment_expression
942    ;
943
944glsl_assignment_expression:
945    glsl_conditional_expression
946  | glsl_unary_expression glsl_assignment_operator glsl_assignment_expression
947    ;
948
949glsl_assignment_operator:
950    '='
951  | T_MULEQ
952  | T_DIVEQ
953  | T_MODEQ
954  | T_ADDEQ
955  | T_SUBEQ
956  | T_LEFTEQ
957  | T_RIGHTEQ
958  | T_ANDEQ
959  | T_XOREQ
960  | T_OREQ
961    ;
962
963glsl_expression:
964    glsl_assignment_expression
965  | glsl_expression ',' glsl_assignment_expression
966    ;
967
968glsl_constant_expression:
969    glsl_conditional_expression
970    ;
971
972glsl_declaration:
973    glsl_function_prototype ';'
974  | glsl_init_declarator_list ';'
975  | GT_PRECISION glsl_precision_qualifier glsl_type_specifier_no_prec ';'
976  | glsl_type_qualifier lolfx_identifier '{' glsl_struct_declaration_list '}' ';'
977  | glsl_type_qualifier lolfx_identifier '{' glsl_struct_declaration_list '}' lolfx_identifier ';'
978  | glsl_type_qualifier lolfx_identifier '{' glsl_struct_declaration_list '}' lolfx_identifier '[' ']' ';'
979  | glsl_type_qualifier lolfx_identifier '{' glsl_struct_declaration_list '}' lolfx_identifier '[' glsl_constant_expression ']' ';'
980  | glsl_type_qualifier ';'
981    ;
982
983glsl_function_prototype:
984    glsl_function_declarator ')'
985    ;
986
987glsl_function_declarator:
988    glsl_function_header
989  | glsl_function_header_with_parameters
990    ;
991
992glsl_function_header_with_parameters:
993    glsl_function_header lolfx_parameter_declaration
994  | glsl_function_header_with_parameters ',' lolfx_parameter_declaration
995    ;
996
997glsl_function_header:
998    glsl_fully_specified_type lolfx_identifier '('
999    ;
1000
1001glsl_parameter_declarator:
1002    glsl_type_specifier lolfx_identifier
1003  | glsl_type_specifier lolfx_identifier '[' glsl_constant_expression ']'
1004    ;
1005
1006lolfx_parameter_declaration:
1007    glsl_parameter_declaration ':' lolfx_identifier /* HLSL only */
1008  | glsl_parameter_declaration
1009    ;
1010
1011glsl_parameter_declaration:
1012    glsl_parameter_type_qualifier lolfx_parameter_qualifier glsl_parameter_declarator
1013  | lolfx_parameter_qualifier glsl_parameter_declarator
1014  | glsl_parameter_type_qualifier lolfx_parameter_qualifier glsl_parameter_type_specifier
1015  | lolfx_parameter_qualifier glsl_parameter_type_specifier
1016    ;
1017
1018lolfx_parameter_qualifier:
1019    glsl_parameter_qualifier
1020  | GHT_UNIFORM /* HLSL only */
1021    ;
1022
1023glsl_parameter_qualifier:
1024    /* empty */
1025  | GHT_IN
1026  | GHT_OUT
1027  | GHT_INOUT
1028  | GT_ATTRIBUTE /* deprecated */
1029  | GT_VARYING /* deprecated */
1030    ;
1031
1032glsl_parameter_type_specifier:
1033    glsl_type_specifier
1034    ;
1035
1036glsl_init_declarator_list:
1037    glsl_single_declaration
1038  | glsl_init_declarator_list ',' lolfx_identifier
1039  | glsl_init_declarator_list ',' lolfx_identifier '[' ']'
1040  | glsl_init_declarator_list ',' lolfx_identifier '[' glsl_constant_expression ']'
1041  | glsl_init_declarator_list ',' lolfx_identifier '[' ']' '=' glsl_initializer
1042  | glsl_init_declarator_list ',' lolfx_identifier '[' glsl_constant_expression ']' '=' glsl_initializer
1043  | glsl_init_declarator_list ',' lolfx_identifier '=' glsl_initializer
1044    ;
1045
1046glsl_single_declaration:
1047    glsl_fully_specified_type
1048  | glsl_fully_specified_type lolfx_identifier
1049  | glsl_fully_specified_type lolfx_identifier '[' ']'
1050  | glsl_fully_specified_type lolfx_identifier '[' glsl_constant_expression ']'
1051  | glsl_fully_specified_type lolfx_identifier '[' ']' '=' glsl_initializer
1052  | glsl_fully_specified_type lolfx_identifier '[' glsl_constant_expression ']' '=' glsl_initializer
1053  | glsl_fully_specified_type lolfx_identifier '=' glsl_initializer
1054  | GT_INVARIANT lolfx_identifier
1055    ;
1056
1057glsl_fully_specified_type:
1058    glsl_type_specifier
1059  | glsl_type_qualifier glsl_type_specifier
1060    ;
1061
1062glsl_invariant_qualifier:
1063    GT_INVARIANT
1064    ;
1065
1066glsl_interpolation_qualifier:
1067    GT_SMOOTH
1068  | GT_FLAT
1069  | GHT_NOPERSPECTIVE
1070    ;
1071
1072glsl_layout_qualifier:
1073    GT_LAYOUT '(' glsl_layout_qualifier_id_list ')'
1074    ;
1075
1076glsl_layout_qualifier_id_list:
1077    glsl_layout_qualifier_id
1078  | glsl_layout_qualifier_id_list ',' glsl_layout_qualifier_id
1079    ;
1080
1081glsl_layout_qualifier_id:
1082    lolfx_identifier
1083  | lolfx_identifier '=' INTCONSTANT
1084    ;
1085
1086glsl_parameter_type_qualifier:
1087    GHT_CONST
1088    ;
1089
1090glsl_type_qualifier:
1091    glsl_storage_qualifier
1092  | glsl_layout_qualifier
1093  | glsl_layout_qualifier glsl_storage_qualifier
1094  | glsl_interpolation_qualifier glsl_storage_qualifier
1095  | glsl_interpolation_qualifier
1096  | glsl_invariant_qualifier glsl_storage_qualifier
1097  | glsl_invariant_qualifier glsl_interpolation_qualifier glsl_storage_qualifier
1098  | glsl_invariant_qualifier
1099    ;
1100
1101glsl_storage_qualifier:
1102    GHT_CONST
1103  | GHT_IN
1104  | GHT_OUT
1105  | GHT_CENTROID GHT_IN
1106  | GHT_CENTROID GHT_OUT
1107  | GT_PATCH GHT_IN
1108  | GT_PATCH GHT_OUT
1109  | GT_SAMPLE GHT_IN
1110  | GT_SAMPLE GHT_OUT
1111  | GHT_UNIFORM
1112  | GT_ATTRIBUTE /* deprecated */
1113  | GT_VARYING /* deprecated */
1114    ;
1115
1116glsl_type_specifier:
1117    glsl_type_specifier_no_prec
1118  | glsl_precision_qualifier glsl_type_specifier_no_prec
1119    ;
1120
1121glsl_type_specifier_no_prec:
1122    lolfx_type_specifier_nonarray
1123  | lolfx_type_specifier_nonarray '[' ']'
1124  | lolfx_type_specifier_nonarray '[' glsl_constant_expression ']'
1125
1126lolfx_type_specifier_nonarray:
1127    glsl_type_specifier_nonarray
1128  | group_hlsl_type /* HLSL only */
1129    ;
1130
1131glsl_type_specifier_nonarray:
1132    GHT_VOID
1133  | GHT_FLOAT
1134  | GHT_DOUBLE
1135  | GHT_INT
1136  | GHT_UINT
1137  | GHT_BOOL
1138  | group_glsl_type
1139  | GHT_SAMPLER1D
1140  | GHT_SAMPLER2D
1141  | GHT_SAMPLER3D
1142  | GHT_SAMPLERCUBE
1143  | glsl_struct_specifier
1144  | TYPENAME
1145    ;
1146
1147glsl_precision_qualifier:
1148    GT_HIGHP
1149  | GT_MEDIUMP
1150  | GT_LOWP
1151    ;
1152
1153glsl_struct_specifier:
1154    GHT_STRUCT lolfx_identifier '{' glsl_struct_declaration_list '}'
1155  | GHT_STRUCT '{' glsl_struct_declaration_list '}'
1156    ;
1157
1158glsl_struct_declaration_list:
1159    glsl_struct_declaration
1160  | glsl_struct_declaration_list glsl_struct_declaration
1161    ;
1162
1163glsl_struct_declaration:
1164    glsl_type_specifier glsl_struct_declarator_list ';'
1165  | glsl_type_qualifier glsl_type_specifier glsl_struct_declarator_list ';'
1166    ;
1167
1168glsl_struct_declarator_list:
1169    glsl_struct_declarator
1170  | glsl_struct_declarator_list ',' glsl_struct_declarator
1171    ;
1172
1173glsl_struct_declarator:
1174    lolfx_identifier
1175  | lolfx_identifier '[' ']'
1176  | lolfx_identifier '[' glsl_constant_expression ']'
1177    ;
1178
1179glsl_initializer:
1180    glsl_assignment_expression
1181    ;
1182
1183glsl_declaration_statement:
1184    glsl_declaration
1185    ;
1186
1187glsl_statement:
1188    glsl_compound_statement
1189  | glsl_simple_statement
1190    ;
1191
1192glsl_simple_statement:
1193    glsl_declaration_statement
1194  | glsl_expression_statement
1195  | glsl_selection_statement
1196  | glsl_switch_statement
1197  | glsl_case_label
1198  | glsl_iteration_statement
1199  | glsl_jump_statement
1200    ;
1201
1202glsl_compound_statement:
1203    '{' '}'
1204  | '{' glsl_statement_list '}'
1205    ;
1206
1207glsl_statement_no_new_scope:
1208    glsl_compound_statement_no_new_scope
1209  | glsl_simple_statement
1210    ;
1211
1212glsl_compound_statement_no_new_scope:
1213    '{' '}'
1214  | '{' glsl_statement_list '}'
1215    ;
1216
1217glsl_statement_list:
1218    glsl_statement
1219  | glsl_statement_list glsl_statement
1220    ;
1221
1222glsl_expression_statement:
1223    ';'
1224  | glsl_expression ';'
1225    ;
1226
1227glsl_selection_statement:
1228    GHT_IF '(' glsl_expression ')' glsl_selection_rest_statement
1229    ;
1230
1231glsl_selection_rest_statement:
1232    glsl_statement GHT_ELSE glsl_statement
1233  | glsl_statement
1234    ;
1235
1236glsl_condition:
1237    glsl_expression
1238  | glsl_fully_specified_type lolfx_identifier '=' glsl_initializer
1239    ;
1240
1241glsl_switch_statement:
1242    GHT_SWITCH '(' glsl_expression ')' '{' glsl_switch_statement_list '}'
1243    ;
1244
1245glsl_switch_statement_list:
1246    /* nothing */
1247  | glsl_statement_list
1248    ;
1249
1250glsl_case_label:
1251    GHT_CASE glsl_expression ':'
1252  | GHT_DEFAULT ':'
1253    ;
1254
1255glsl_iteration_statement:
1256    GHT_WHILE '(' glsl_condition ')' glsl_statement_no_new_scope
1257  | GHT_DO glsl_statement GHT_WHILE '(' glsl_expression ')' ';'
1258  | GHT_FOR '(' glsl_for_init_statement glsl_for_rest_statement ')' glsl_statement_no_new_scope
1259    ;
1260
1261glsl_for_init_statement:
1262    glsl_expression_statement
1263  | glsl_declaration_statement
1264    ;
1265
1266glsl_conditionopt:
1267    glsl_condition
1268  | /* empty */
1269    ;
1270
1271glsl_for_rest_statement:
1272    glsl_conditionopt ';'
1273  | glsl_conditionopt ';' glsl_expression
1274    ;
1275
1276glsl_jump_statement:
1277    GHT_CONTINUE ';'
1278  | GHT_BREAK ';'
1279  | GHT_RETURN ';'
1280  | GHT_RETURN glsl_expression ';'
1281  | GHT_DISCARD ';'
1282    ;
1283
1284glsl_translation_unit:
1285    glsl_external_declaration
1286  | glsl_translation_unit glsl_external_declaration
1287    ;
1288
1289glsl_external_declaration:
1290    glsl_function_definition
1291  | glsl_declaration
1292    ;
1293
1294glsl_function_definition:
1295    glsl_function_prototype glsl_compound_statement_no_new_scope
1296    ;
1297
1298%%
1299
1300void lol::LolFxParser::error(const LolFxParser::location_type& l,
1301                             const std::string& m)
1302{
1303    mc.Error(l, m);
1304}
1305
Note: See TracBrowser for help on using the repository browser.