glsl.lex 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. %{
  2. #include <math.h>
  3. #include <stdbool.h>
  4. #include <string.h>
  5. #define YYSTYPE GLSL_STYPE
  6. #define YYLTYPE GLSL_LTYPE
  7. #define YY_USER_ACTION \
  8. yylloc->first_line = yylloc->last_line; \
  9. yylloc->first_column = yylloc->last_column; \
  10. { \
  11. int i; \
  12. for(i = 0; yytext[i] != '\0'; i++) { \
  13. if(yytext[i] == '\n') { \
  14. yylloc->last_line++; \
  15. yylloc->last_column = 0; \
  16. } \
  17. else { \
  18. yylloc->last_column++; \
  19. } \
  20. } \
  21. }
  22. #include "glsl_parser.h"
  23. #include "glsl.parser.h"
  24. %}
  25. %option reentrant
  26. %option bison-bridge
  27. %option bison-locations
  28. %option yylineno
  29. %option noyywrap
  30. %option prefix="glsl_"
  31. ws [ \t]+
  32. digit [0-9]
  33. nondigit [_a-zA-Z]
  34. identifier {nondigit}({nondigit}|{digit})*
  35. integer_constant {digit}+
  36. floating_constant {digit}+\.{digit}+
  37. %x COMMENT
  38. %%
  39. [\t\n ]+
  40. #.*\n
  41. \/\/.*\n
  42. <INITIAL>"/*" BEGIN(COMMENT);
  43. <COMMENT>"*/" BEGIN(INITIAL);
  44. <COMMENT>[^*\n]+ { }
  45. const return CONST;
  46. uniform return UNIFORM;
  47. buffer return BUFFER;
  48. shared return SHARED;
  49. coherent return COHERENT;
  50. volatile return VOLATILE;
  51. restrict return RESTRICT;
  52. readonly return READONLY;
  53. writeonly return WRITEONLY;
  54. atomic_uint return ATOMIC_UINT;
  55. layout return LAYOUT;
  56. centroid return CENTROID;
  57. flat return FLAT;
  58. smooth return SMOOTH;
  59. noperspective return NOPERSPECTIVE;
  60. patch return PATCH;
  61. sample return SAMPLE;
  62. break return BREAK;
  63. continue return CONTINUE;
  64. do return DO;
  65. for return FOR;
  66. while return WHILE;
  67. switch return SWITCH;
  68. case return CASE;
  69. default return DEFAULT;
  70. if return IF;
  71. else return ELSE;
  72. subroutine return SUBROUTINE;
  73. in return IN;
  74. out return OUT;
  75. inout return INOUT;
  76. float return FLOAT;
  77. double return DOUBLE;
  78. int return INT;
  79. void return VOID;
  80. bool return BOOL;
  81. invariant return INVARIANT;
  82. precise return PRECISE;
  83. discard return DISCARD;
  84. return return RETURN;
  85. mat2 return MAT2;
  86. mat3 return MAT3;
  87. mat4 return MAT4;
  88. dmat2 return DMAT2;
  89. dmat3 return DMAT3;
  90. dmat4 return DMAT4;
  91. mat2x2 return MAT2X2;
  92. mat2x3 return MAT2X3;
  93. mat2x4 return MAT2X4;
  94. dmat2x2 return DMAT2X2;
  95. dmat2x3 return DMAT2X3;
  96. dmat2x4 return DMAT2X4;
  97. mat3x2 return MAT3X2;
  98. mat3x3 return MAT3X3;
  99. mat3x4 return MAT3X4;
  100. dmat3x2 return DMAT3X2;
  101. dmat3x3 return DMAT3X3;
  102. dmat3x4 return DMAT3X4;
  103. mat4x2 return MAT4X2;
  104. mat4x3 return MAT4X3;
  105. mat4x4 return MAT4X4;
  106. dmat4x2 return DMAT4X2;
  107. dmat4x3 return DMAT4X3;
  108. dmat4x4 return DMAT4X4;
  109. vec2 return VEC2;
  110. vec3 return VEC3;
  111. vec4 return VEC4;
  112. ivec2 return IVEC2;
  113. ivec3 return IVEC3;
  114. ivec4 return IVEC4;
  115. bvec2 return BVEC2;
  116. bvec3 return BVEC3;
  117. bvec4 return BVEC4;
  118. dvec2 return DVEC2;
  119. dvec3 return DVEC3;
  120. dvec4 return DVEC4;
  121. uint return UINT;
  122. uvec2 return UVEC2;
  123. uvec3 return UVEC3;
  124. uvec4 return UVEC4;
  125. lowp return LOWP;
  126. mediump return MEDIUMP;
  127. highp return HIGHP;
  128. precision return PRECISION;
  129. sampler1D return SAMPLER1D;
  130. sampler2D return SAMPLER2D;
  131. sampler3D return SAMPLER3D;
  132. samplerCube return SAMPLERCUBE;
  133. sampler1DShadow return SAMPLER1DSHADOW;
  134. sampler2DShadow return SAMPLER2DSHADOW;
  135. samplerCubeShadow return SAMPLERCUBESHADOW;
  136. sampler1DArray return SAMPLER1DARRAY;
  137. sampler2DArray return SAMPLER2DARRAY;
  138. sampler1DArrayShadow return SAMPLER1DARRAYSHADOW;
  139. sampler2DArrayShadow return SAMPLER2DARRAYSHADOW;
  140. isampler1D return ISAMPLER1D;
  141. isampler2D return ISAMPLER2D;
  142. isampler3D return ISAMPLER3D;
  143. isamplerCube return ISAMPLERCUBE;
  144. isampler1DArray return ISAMPLER1DARRAY;
  145. isampler2DArray return ISAMPLER2DARRAY;
  146. usampler1D return USAMPLER1D;
  147. usampler2D return USAMPLER2D;
  148. usampler3D return USAMPLER3D;
  149. usamplerCube return USAMPLERCUBE;
  150. usampler1DArray return USAMPLER1DARRAY;
  151. usampler2DArray return USAMPLER2DARRAY;
  152. sampler2DRect return SAMPLER2DRECT;
  153. sampler2DRectShadow return SAMPLER2DRECTSHADOW;
  154. isampler2DRect return ISAMPLER2DRECT;
  155. usampler2DRect return USAMPLER2DRECT;
  156. samplerBuffer return SAMPLERBUFFER;
  157. isamplerBuffer return ISAMPLERBUFFER;
  158. usamplerBuffer return USAMPLERBUFFER;
  159. sampler2DMS return SAMPLER2DMS;
  160. isampler2DMS return ISAMPLER2DMS;
  161. usampler2DMS return USAMPLER2DMS;
  162. sampler2DMSArray return SAMPLER2DMSARRAY;
  163. isampler2DMSArray return ISAMPLER2DMSARRAY;
  164. usampler2DMSArray return USAMPLER2DMSARRAY;
  165. samplerCubeArray return SAMPLERCUBEARRAY;
  166. samplerCubeArrayShadow return SAMPLERCUBEARRAYSHADOW;
  167. isamplerCubeArray return ISAMPLERCUBEARRAY;
  168. usamplerCubeArray return USAMPLERCUBEARRAY;
  169. image1D return IMAGE1D;
  170. iimage1D return IIMAGE1D;
  171. uimage1D return UIMAGE1D;
  172. image2D return IMAGE2D;
  173. iimage2D return IIMAGE2D;
  174. uimage2D return UIMAGE2D;
  175. image3D return IMAGE3D;
  176. iimage3D return IIMAGE3D;
  177. uimage3D return UIMAGE3D;
  178. image2DRect return IMAGE2DRECT;
  179. iimage2DRect return IIMAGE2DRECT;
  180. uimage2DRect return UIMAGE2DRECT;
  181. imageCube return IMAGECUBE;
  182. iimageCube return IIMAGECUBE;
  183. uimageCube return UIMAGECUBE;
  184. imageBuffer return IMAGEBUFFER;
  185. iimageBuffer return IIMAGEBUFFER;
  186. uimageBuffer return UIMAGEBUFFER;
  187. image1DArray return IMAGE1DARRAY;
  188. iimage1DArray return IIMAGE1DARRAY;
  189. uimage1DArray return UIMAGE1DARRAY;
  190. image2DArray return IMAGE2DARRAY;
  191. iimage2DArray return IIMAGE2DARRAY;
  192. uimage2DArray return UIMAGE2DARRAY;
  193. imageCubeArray return IMAGECUBEARRAY;
  194. iimageCubeArray return IIMAGECUBEARRAY;
  195. uimageCubeArray return UIMAGECUBEARRAY;
  196. image2DMS return IMAGE2DMS;
  197. iimage2DMS return IIMAGE2DMS;
  198. uimage2DMS return UIMAGE2DMS;
  199. image2DMSArray return IMAGE2DMSARRAY;
  200. iimage2DMSArray return IIMAGE2DMSARRAY;
  201. uimage2DMSArray return UIMAGE2DMSARRAY;
  202. struct return STRUCT;
  203. section return SECTION;
  204. \<\< return LEFT_OP;
  205. \>\> return RIGHT_OP;
  206. \+\+ return INC_OP;
  207. \-\- return DEC_OP;
  208. \<\= return LE_OP;
  209. \>\= return GE_OP;
  210. \=\= return EQ_OP;
  211. \!\= return NE_OP;
  212. \&\& return AND_OP;
  213. \|\| return OR_OP;
  214. \^\^ return XOR_OP;
  215. \*\= return MUL_ASSIGN;
  216. \/\= return DIV_ASSIGN;
  217. \+\= return ADD_ASSIGN;
  218. \%\= return MOD_ASSIGN;
  219. \<\<\= return LEFT_ASSIGN;
  220. \>\>\= return RIGHT_ASSIGN;
  221. \&\= return AND_ASSIGN;
  222. \^\= return XOR_ASSIGN;
  223. \|\= return OR_ASSIGN;
  224. \-\= return SUB_ASSIGN;
  225. \+ return PLUS;
  226. \- return DASH;
  227. \% return PERCENT;
  228. \* return STAR;
  229. \/ return SLASH;
  230. \~ return TILDE;
  231. \! return BANG;
  232. \^ return CARET;
  233. \( return LEFT_PAREN;
  234. \) return RIGHT_PAREN;
  235. \{ return LEFT_BRACE;
  236. \} return RIGHT_BRACE;
  237. \; return SEMICOLON;
  238. \< return LEFT_ANGLE;
  239. \> return RIGHT_ANGLE;
  240. \. return DOT;
  241. \, return COMMA;
  242. \[ return LEFT_BRACKET;
  243. \] return RIGHT_BRACKET;
  244. \| return VERTICAL_BAR;
  245. \: return COLON;
  246. \= return EQUAL;
  247. \& return AMPERSAND;
  248. \? return QUESTION;
  249. true { return TRUE_VALUE; }
  250. false { return FALSE_VALUE; }
  251. {identifier} { (*yylval).IDENTIFIER = strdup(yytext); return IDENTIFIER; }
  252. {integer_constant} { (*yylval).INTCONSTANT = atoi(yytext); return INTCONSTANT; }
  253. {floating_constant} { (*yylval).FLOATCONSTANT = atof(yytext); return FLOATCONSTANT; }
  254. %%