glsl.lex 6.6 KB

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