Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glsl_lexer.lpp 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. %{
  2. /*
  3. * Copyright © 2008, 2009 Intel Corporation
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include "ast.h"
  25. #include "glsl_parser_extras.h"
  26. #include "glsl_parser.h"
  27. #define YY_USER_ACTION \
  28. do { \
  29. yylloc->source = 0; \
  30. yylloc->first_column = yycolumn + 1; \
  31. yylloc->first_line = yylineno + 1; \
  32. yycolumn += yyleng; \
  33. } while(0);
  34. %}
  35. %option bison-bridge bison-locations reentrant noyywrap
  36. %option never-interactive
  37. %option prefix="_mesa_glsl_"
  38. %option extra-type="struct _mesa_glsl_parse_state *"
  39. %option stack
  40. %x PP COMMENT
  41. %%
  42. "/*" { yy_push_state(COMMENT, yyscanner); }
  43. <COMMENT>[^*\n]*
  44. <COMMENT>[^*\n]*\n { yylineno++; yycolumn = 0; }
  45. <COMMENT>"*"+[^*/\n]*
  46. <COMMENT>"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; }
  47. <COMMENT>"*"+"/" { yy_pop_state(yyscanner); }
  48. \/\/.*\n { yylineno++; yycolumn = 0; }
  49. [ \r\t]+ ;
  50. /* Preprocessor tokens. */
  51. ^[ \t]*#[ \t]*$ ;
  52. ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; }
  53. ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
  54. ^[ \t]*#[ \t]*line { BEGIN PP; return LINE; }
  55. ^[ \t]*#[ \t]*pragma { BEGIN PP; return PRAGMA; }
  56. <PP>: return COLON;
  57. <PP>[_a-zA-Z][_a-zA-Z0-9]* {
  58. yylval->identifier = strdup(yytext);
  59. return IDENTIFIER;
  60. }
  61. <PP>[1-9][0-9]* {
  62. yylval->n = strtol(yytext, NULL, 10);
  63. return INTCONSTANT;
  64. }
  65. <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
  66. \n { yylineno++; yycolumn = 0; }
  67. attribute return ATTRIBUTE;
  68. const return CONST;
  69. bool return BOOL;
  70. float return FLOAT;
  71. int return INT;
  72. break return BREAK;
  73. continue return CONTINUE;
  74. do return DO;
  75. while return WHILE;
  76. else return ELSE;
  77. for return FOR;
  78. if return IF;
  79. discard return DISCARD;
  80. return return RETURN;
  81. bvec2 return BVEC2;
  82. bvec3 return BVEC3;
  83. bvec4 return BVEC4;
  84. ivec2 return IVEC2;
  85. ivec3 return IVEC3;
  86. ivec4 return IVEC4;
  87. vec2 return VEC2;
  88. vec3 return VEC3;
  89. vec4 return VEC4;
  90. mat2 return MAT2;
  91. mat3 return MAT3;
  92. mat4 return MAT4;
  93. mat2x2 return MAT2X2;
  94. mat2x3 return MAT2X3;
  95. mat2x4 return MAT2X4;
  96. mat3x2 return MAT3X2;
  97. mat3x3 return MAT3X3;
  98. mat3x4 return MAT3X4;
  99. mat4x2 return MAT4X2;
  100. mat4x3 return MAT4X3;
  101. mat4x4 return MAT4X4;
  102. in return IN;
  103. out return OUT;
  104. inout return INOUT;
  105. uniform return UNIFORM;
  106. varying return VARYING;
  107. centroid return CENTROID;
  108. invariant return INVARIANT;
  109. sampler1D return SAMPLER1D;
  110. sampler2D return SAMPLER2D;
  111. sampler3D return SAMPLER3D;
  112. samplerCube return SAMPLERCUBE;
  113. sampler1DShadow return SAMPLER1DSHADOW;
  114. sampler2DShadow return SAMPLER2DSHADOW;
  115. struct return STRUCT;
  116. void return VOID;
  117. \+\+ return INC_OP;
  118. -- return DEC_OP;
  119. \<= return LE_OP;
  120. >= return GE_OP;
  121. == return EQ_OP;
  122. != return NE_OP;
  123. && return AND_OP;
  124. \|\| return OR_OP;
  125. "^^" return XOR_OP;
  126. \*= return MUL_ASSIGN;
  127. \/= return DIV_ASSIGN;
  128. \+= return ADD_ASSIGN;
  129. \%= return MOD_ASSIGN;
  130. \<\<= return LEFT_ASSIGN;
  131. >>= return RIGHT_ASSIGN;
  132. &= return AND_ASSIGN;
  133. ^= return XOR_ASSIGN;
  134. \|= return OR_ASSIGN;
  135. -= return SUB_ASSIGN;
  136. [1-9][0-9]* {
  137. yylval->n = strtol(yytext, NULL, 10);
  138. return INTCONSTANT;
  139. }
  140. 0[xX][0-9a-fA-F]+ {
  141. yylval->n = strtol(yytext + 2, NULL, 16);
  142. return INTCONSTANT;
  143. }
  144. 0[0-7]* {
  145. yylval->n = strtol(yytext + 2, NULL, 8);
  146. return INTCONSTANT;
  147. }
  148. [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
  149. yylval->real = strtod(yytext, NULL);
  150. return FLOATCONSTANT;
  151. }
  152. \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
  153. yylval->real = strtod(yytext, NULL);
  154. return FLOATCONSTANT;
  155. }
  156. [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
  157. yylval->real = strtod(yytext, NULL);
  158. return FLOATCONSTANT;
  159. }
  160. [0-9]+[eE][+-]?[0-9]+[fF]? {
  161. yylval->real = strtod(yytext, NULL);
  162. return FLOATCONSTANT;
  163. }
  164. true {
  165. yylval->n = 1;
  166. return BOOLCONSTANT;
  167. }
  168. false {
  169. yylval->n = 0;
  170. return BOOLCONSTANT;
  171. }
  172. /* Reserved words in GLSL 1.10. */
  173. asm return ASM;
  174. class return CLASS;
  175. union return UNION;
  176. enum return ENUM;
  177. typedef return TYPEDEF;
  178. template return TEMPLATE;
  179. this return THIS;
  180. packed return PACKED;
  181. goto return GOTO;
  182. switch return SWITCH;
  183. default return DEFAULT;
  184. inline return INLINE;
  185. noinline return NOINLINE;
  186. volatile return VOLATILE;
  187. public return PUBLIC;
  188. static return STATIC;
  189. extern return EXTERN;
  190. external return EXTERNAL;
  191. interface return INTERFACE;
  192. long return LONG;
  193. short return SHORT;
  194. double return DOUBLE;
  195. half return HALF;
  196. fixed return FIXED;
  197. unsigned return UNSIGNED;
  198. input return INPUT;
  199. output return OUTPUT;
  200. hvec2 return HVEC2;
  201. hvec3 return HVEC3;
  202. hvec4 return HVEC4;
  203. dvec2 return DVEC2;
  204. dvec3 return DVEC3;
  205. dvec4 return DVEC4;
  206. fvec2 return FVEC2;
  207. fvec3 return FVEC3;
  208. fvec4 return FVEC4;
  209. sampler2DRect return SAMPLER2DRECT;
  210. sampler3DRect return SAMPLER3DRECT;
  211. sampler2DRectShadow return SAMPLER2DRECTSHADOW;
  212. sizeof return SIZEOF;
  213. cast return CAST;
  214. namespace return NAMESPACE;
  215. using return USING;
  216. /* Additional reserved words in GLSL 1.20. */
  217. lowp return LOWP;
  218. mediump return MEDIUMP;
  219. highp return HIGHP;
  220. precision return PRECISION;
  221. [_a-zA-Z][_a-zA-Z0-9]* {
  222. yylval->identifier = strdup(yytext);
  223. return IDENTIFIER;
  224. }
  225. . { return yytext[0]; }
  226. %%
  227. void
  228. _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
  229. const char *string, size_t len)
  230. {
  231. yylex_init_extra(state, & state->scanner);
  232. yy_scan_bytes(string, len, state->scanner);
  233. }
  234. void
  235. _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
  236. {
  237. yylex_destroy(state->scanner);
  238. }