Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

glsl_lexer.lpp 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. #include "symbol_table.h"
  28. #define YY_USER_ACTION \
  29. do { \
  30. yylloc->source = 0; \
  31. yylloc->first_column = yycolumn + 1; \
  32. yylloc->first_line = yylineno + 1; \
  33. yycolumn += yyleng; \
  34. } while(0);
  35. %}
  36. %option bison-bridge bison-locations reentrant noyywrap
  37. %option never-interactive
  38. %option prefix="_mesa_glsl_"
  39. %option extra-type="struct _mesa_glsl_parse_state *"
  40. %option stack
  41. %x PP COMMENT
  42. %%
  43. "/*" { yy_push_state(COMMENT, yyscanner); }
  44. <COMMENT>[^*\n]*
  45. <COMMENT>[^*\n]*\n { yylineno++; yycolumn = 0; }
  46. <COMMENT>"*"+[^*/\n]*
  47. <COMMENT>"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; }
  48. <COMMENT>"*"+"/" { yy_pop_state(yyscanner); }
  49. \/\/.*\n { yylineno++; yycolumn = 0; }
  50. [ \r\t]+ ;
  51. /* Preprocessor tokens. */
  52. ^[ \t]*#[ \t]*$ ;
  53. ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; }
  54. ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
  55. ^[ \t]*#[ \t]*line { BEGIN PP; return LINE; }
  56. ^[ \t]*#[ \t]*pragma { BEGIN PP; return PRAGMA; }
  57. <PP>: return COLON;
  58. <PP>[_a-zA-Z][_a-zA-Z0-9]* {
  59. yylval->identifier = strdup(yytext);
  60. return IDENTIFIER;
  61. }
  62. <PP>[1-9][0-9]* {
  63. yylval->n = strtol(yytext, NULL, 10);
  64. return INTCONSTANT;
  65. }
  66. <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
  67. \n { yylineno++; yycolumn = 0; }
  68. attribute return ATTRIBUTE;
  69. const return CONST;
  70. bool return BOOL;
  71. float return FLOAT;
  72. int return INT;
  73. break return BREAK;
  74. continue return CONTINUE;
  75. do return DO;
  76. while return WHILE;
  77. else return ELSE;
  78. for return FOR;
  79. if return IF;
  80. discard return DISCARD;
  81. return return RETURN;
  82. bvec2 return BVEC2;
  83. bvec3 return BVEC3;
  84. bvec4 return BVEC4;
  85. ivec2 return IVEC2;
  86. ivec3 return IVEC3;
  87. ivec4 return IVEC4;
  88. vec2 return VEC2;
  89. vec3 return VEC3;
  90. vec4 return VEC4;
  91. mat2 return MAT2;
  92. mat3 return MAT3;
  93. mat4 return MAT4;
  94. mat2x2 return MAT2X2;
  95. mat2x3 return MAT2X3;
  96. mat2x4 return MAT2X4;
  97. mat3x2 return MAT3X2;
  98. mat3x3 return MAT3X3;
  99. mat3x4 return MAT3X4;
  100. mat4x2 return MAT4X2;
  101. mat4x3 return MAT4X3;
  102. mat4x4 return MAT4X4;
  103. in return IN;
  104. out return OUT;
  105. inout return INOUT;
  106. uniform return UNIFORM;
  107. varying return VARYING;
  108. centroid return CENTROID;
  109. invariant return INVARIANT;
  110. sampler1D return SAMPLER1D;
  111. sampler2D return SAMPLER2D;
  112. sampler3D return SAMPLER3D;
  113. samplerCube return SAMPLERCUBE;
  114. sampler1DShadow return SAMPLER1DSHADOW;
  115. sampler2DShadow return SAMPLER2DSHADOW;
  116. struct return STRUCT;
  117. void return VOID;
  118. \+\+ return INC_OP;
  119. -- return DEC_OP;
  120. \<= return LE_OP;
  121. >= return GE_OP;
  122. == return EQ_OP;
  123. != return NE_OP;
  124. && return AND_OP;
  125. \|\| return OR_OP;
  126. "^^" return XOR_OP;
  127. \*= return MUL_ASSIGN;
  128. \/= return DIV_ASSIGN;
  129. \+= return ADD_ASSIGN;
  130. \%= return MOD_ASSIGN;
  131. \<\<= return LEFT_ASSIGN;
  132. >>= return RIGHT_ASSIGN;
  133. &= return AND_ASSIGN;
  134. ^= return XOR_ASSIGN;
  135. \|= return OR_ASSIGN;
  136. -= return SUB_ASSIGN;
  137. [1-9][0-9]* {
  138. yylval->n = strtol(yytext, NULL, 10);
  139. return INTCONSTANT;
  140. }
  141. 0[xX][0-9a-fA-F]+ {
  142. yylval->n = strtol(yytext + 2, NULL, 16);
  143. return INTCONSTANT;
  144. }
  145. 0[0-7]* {
  146. yylval->n = strtol(yytext + 2, NULL, 8);
  147. return INTCONSTANT;
  148. }
  149. [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
  150. yylval->real = strtod(yytext, NULL);
  151. return FLOATCONSTANT;
  152. }
  153. \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
  154. yylval->real = strtod(yytext, NULL);
  155. return FLOATCONSTANT;
  156. }
  157. [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
  158. yylval->real = strtod(yytext, NULL);
  159. return FLOATCONSTANT;
  160. }
  161. [0-9]+[eE][+-]?[0-9]+[fF]? {
  162. yylval->real = strtod(yytext, NULL);
  163. return FLOATCONSTANT;
  164. }
  165. true {
  166. yylval->n = 1;
  167. return BOOLCONSTANT;
  168. }
  169. false {
  170. yylval->n = 0;
  171. return BOOLCONSTANT;
  172. }
  173. /* Reserved words in GLSL 1.10. */
  174. asm return ASM;
  175. class return CLASS;
  176. union return UNION;
  177. enum return ENUM;
  178. typedef return TYPEDEF;
  179. template return TEMPLATE;
  180. this return THIS;
  181. packed return PACKED;
  182. goto return GOTO;
  183. switch return SWITCH;
  184. default return DEFAULT;
  185. inline return INLINE;
  186. noinline return NOINLINE;
  187. volatile return VOLATILE;
  188. public return PUBLIC;
  189. static return STATIC;
  190. extern return EXTERN;
  191. external return EXTERNAL;
  192. interface return INTERFACE;
  193. long return LONG;
  194. short return SHORT;
  195. double return DOUBLE;
  196. half return HALF;
  197. fixed return FIXED;
  198. unsigned return UNSIGNED;
  199. input return INPUT;
  200. output return OUTPUT;
  201. hvec2 return HVEC2;
  202. hvec3 return HVEC3;
  203. hvec4 return HVEC4;
  204. dvec2 return DVEC2;
  205. dvec3 return DVEC3;
  206. dvec4 return DVEC4;
  207. fvec2 return FVEC2;
  208. fvec3 return FVEC3;
  209. fvec4 return FVEC4;
  210. sampler2DRect return SAMPLER2DRECT;
  211. sampler3DRect return SAMPLER3DRECT;
  212. sampler2DRectShadow return SAMPLER2DRECTSHADOW;
  213. sizeof return SIZEOF;
  214. cast return CAST;
  215. namespace return NAMESPACE;
  216. using return USING;
  217. /* Additional reserved words in GLSL 1.20. */
  218. lowp return LOWP;
  219. mediump return MEDIUMP;
  220. highp return HIGHP;
  221. precision return PRECISION;
  222. [_a-zA-Z][_a-zA-Z0-9]* {
  223. yylval->identifier = strdup(yytext);
  224. if (_mesa_symbol_table_find_symbol(yyextra->symbols,
  225. 0,
  226. yylval->identifier))
  227. return TYPE_NAME;
  228. else
  229. return IDENTIFIER;
  230. }
  231. . { return yytext[0]; }
  232. %%
  233. void
  234. _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
  235. const char *string, size_t len)
  236. {
  237. yylex_init_extra(state, & state->scanner);
  238. yy_scan_bytes(string, len, state->scanner);
  239. }
  240. void
  241. _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
  242. {
  243. yylex_destroy(state->scanner);
  244. }