Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

glsl_lexer.lpp 6.5KB

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