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

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

build: fix PS3 and Android builds.

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