選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

562 行
24 KiB

  1. %{
  2. #include <iostream>
  3. #define YY_DECL extern "C" int yylex()
  4. #include "lolfx.tab.h"
  5. %}
  6. %x GLSL
  7. %x HLSL
  8. %x C_COMMENT
  9. %x CPP_COMMENT
  10. %%
  11. %{
  12. int comment_caller = INITIAL;
  13. %}
  14. /*
  15. * GLSL keywords
  16. */
  17. "subroutine" { return GT_SUBROUTINE; }
  18. "patch" { return GT_PATCH; }
  19. "sample" { return GT_SAMPLE; }
  20. "flat" { return GT_FLAT; }
  21. "smooth" { return GT_SMOOTH; }
  22. "layout" { return GT_LAYOUT; }
  23. "sampler1dshadow" { return GT_SAMPLER1DSHADOW; }
  24. "sampler2dshadow" { return GT_SAMPLER2DSHADOW; }
  25. "samplercubeshadow" { return GT_SAMPLERCUBESHADOW; }
  26. "sampler1darray" { return GT_SAMPLER1DARRAY; }
  27. "sampler2darray" { return GT_SAMPLER2DARRAY; }
  28. "sampler1darrayshadow" { return GT_SAMPLER1DARRAYSHADOW; }
  29. "sampler2darrayshadow" { return GT_SAMPLER2DARRAYSHADOW; }
  30. "isampler1d" { return GT_ISAMPLER1D; }
  31. "isampler2d" { return GT_ISAMPLER2D; }
  32. "isampler3d" { return GT_ISAMPLER3D; }
  33. "isamplercube" { return GT_ISAMPLERCUBE; }
  34. "isampler1darray" { return GT_ISAMPLER1DARRAY; }
  35. "isampler2darray" { return GT_ISAMPLER2DARRAY; }
  36. "usampler1d" { return GT_USAMPLER1D; }
  37. "usampler2d" { return GT_USAMPLER2D; }
  38. "usampler3d" { return GT_USAMPLER3D; }
  39. "usamplercube" { return GT_USAMPLERCUBE; }
  40. "usampler1darray" { return GT_USAMPLER1DARRAY; }
  41. "usampler2darray" { return GT_USAMPLER2DARRAY; }
  42. "sampler2drect" { return GT_SAMPLER2DRECT; }
  43. "sampler2drectshadow" { return GT_SAMPLER2DRECTSHADOW; }
  44. "isampler2drect" { return GT_ISAMPLER2DRECT; }
  45. "usampler2drect" { return GT_USAMPLER2DRECT; }
  46. "samplerbuffer" { return GT_SAMPLERBUFFER; }
  47. "isamplerbuffer" { return GT_ISAMPLERBUFFER; }
  48. "usamplerbuffer" { return GT_USAMPLERBUFFER; }
  49. "samplercubearray" { return GT_SAMPLERCUBEARRAY; }
  50. "samplercubearrayshadow" { return GT_SAMPLERCUBEARRAYSHADOW; }
  51. "isamplercubearray" { return GT_ISAMPLERCUBEARRAY; }
  52. "usamplercubearray" { return GT_USAMPLERCUBEARRAY; }
  53. "sampler2dms" { return GT_SAMPLER2DMS; }
  54. "isampler2dms" { return GT_ISAMPLER2DMS; }
  55. "usampler2dms" { return GT_USAMPLER2DMS; }
  56. "sampler2dmsarray" { return GT_SAMPLER2DMSARRAY; }
  57. "isampler2dmsarray" { return GT_ISAMPLER2DMSARRAY; }
  58. "usampler2dmsarray" { return GT_USAMPLER2DMSARRAY; }
  59. "highp" { return GT_HIGHP; }
  60. "mediump" { return GT_MEDIUMP; }
  61. "lowp" { return GT_LOWP; }
  62. "precision" { return GT_PRECISION; }
  63. "invariant" { return GT_INVARIANT; }
  64. /*
  65. * Deprecated GLSL keywords
  66. */
  67. "attribute" { return GT_ATTRIBUTE; }
  68. /*
  69. * GLSL vector types
  70. */
  71. "bvec2" { return GT_BVEC2; }
  72. "bvec3" { return GT_BVEC3; }
  73. "bvec4" { return GT_BVEC4; }
  74. "ivec2" { return GT_IVEC2; }
  75. "ivec3" { return GT_IVEC3; }
  76. "ivec4" { return GT_IVEC4; }
  77. "uvec2" { return GT_UVEC2; }
  78. "uvec3" { return GT_UVEC3; }
  79. "uvec4" { return GT_UVEC4; }
  80. "vec2" { return GT_VEC2; }
  81. "vec3" { return GT_VEC3; }
  82. "vec4" { return GT_VEC4; }
  83. "mat2" { return GT_MAT2; }
  84. "mat2x2" { return GT_MAT2X2; }
  85. "mat2x3" { return GT_MAT2X3; }
  86. "mat2x4" { return GT_MAT2X4; }
  87. "mat3" { return GT_MAT3; }
  88. "mat3x2" { return GT_MAT3X2; }
  89. "mat3x3" { return GT_MAT3X3; }
  90. "mat3x4" { return GT_MAT3X4; }
  91. "mat4" { return GT_MAT4; }
  92. "mat4x2" { return GT_MAT4X2; }
  93. "mat4x3" { return GT_MAT4X3; }
  94. "mat4x4" { return GT_MAT4X4; }
  95. "dvec2" { return GT_DVEC2; }
  96. "dvec3" { return GT_DVEC3; }
  97. "dvec4" { return GT_DVEC4; }
  98. "dmat2" { return GT_DMAT2; }
  99. "dmat2x2" { return GT_DMAT2X2; }
  100. "dmat2x3" { return GT_DMAT2X3; }
  101. "dmat2x4" { return GT_DMAT2X4; }
  102. "dmat3" { return GT_DMAT3; }
  103. "dmat3x2" { return GT_DMAT3X2; }
  104. "dmat3x3" { return GT_DMAT3X3; }
  105. "dmat3x4" { return GT_DMAT3X4; }
  106. "dmat4" { return GT_DMAT4; }
  107. "dmat4x2" { return GT_DMAT4X2; }
  108. "dmat4x3" { return GT_DMAT4X3; }
  109. "dmat4x4" { return GT_DMAT4X4; }
  110. /*
  111. * GLSL constant values
  112. */
  113. "true" { yylval.ival = 1; return BOOLCONSTANT; }
  114. "false" { yylval.ival = 0; return BOOLCONSTANT; }
  115. [xyzw]{1,4} { return FIELDSELECTION; }
  116. [rgba]{1,4} { return FIELDSELECTION; }
  117. [stpq]{1,4} { return FIELDSELECTION; }
  118. /*
  119. * GLSL keywords that are also valid or reserved in HLSL
  120. * and HLSL keywords that are also valid or reserved in GLSL.
  121. */
  122. "bool" { return GHT_BOOL; }
  123. "break" { return GHT_BREAK; }
  124. "case" { return GHT_CASE; }
  125. "centroid" { return GHT_CENTROID; }
  126. "const" { return GHT_CONST; }
  127. "continue" { return GHT_CONTINUE; }
  128. "default" { return GHT_DEFAULT; }
  129. "discard" { return GHT_DISCARD; }
  130. "do" { return GHT_DO; }
  131. "double" { return GHT_DOUBLE; }
  132. "else" { return GHT_ELSE; }
  133. "float" { return GHT_FLOAT; }
  134. "for" { return GHT_FOR; }
  135. "if" { return GHT_IF; }
  136. "in" { return GHT_IN; }
  137. "inout" { return GHT_INOUT; }
  138. "int" { return GHT_INT; }
  139. "noperspective" { return GHT_NOPERSPECTIVE; }
  140. "out" { return GHT_OUT; }
  141. "return" { return GHT_RETURN; }
  142. "sampler1d" { return GHT_SAMPLER1D; }
  143. "sampler2d" { return GHT_SAMPLER2D; }
  144. "sampler3d" { return GHT_SAMPLER3D; }
  145. "samplercube" { return GHT_SAMPLERCUBE; }
  146. "struct" { return GHT_STRUCT; }
  147. "switch" { return GHT_SWITCH; }
  148. "uint" { return GHT_UINT; }
  149. "uniform" { return GHT_UNIFORM; }
  150. "void" { return GHT_VOID; }
  151. "while" { return GHT_WHILE; }
  152. (?i:bool) { return HGT_BOOL; }
  153. (?i:break) { return HGT_BREAK; }
  154. (?i:case) { return HGT_CASE; }
  155. (?i:centroid) { return HGT_CENTROID; }
  156. (?i:const) { return HGT_CONST; }
  157. (?i:continue) { return HGT_CONTINUE; }
  158. (?i:default) { return HGT_DEFAULT; }
  159. (?i:discard) { return HGT_DISCARD; }
  160. (?i:do) { return HGT_DO; }
  161. (?i:double) { return HGT_DOUBLE; }
  162. (?i:else) { return HGT_ELSE; }
  163. (?i:float) { return HGT_FLOAT; }
  164. (?i:for) { return HGT_FOR; }
  165. (?i:if) { return HGT_IF; }
  166. (?i:in) { return HGT_IN; }
  167. (?i:inout) { return HGT_INOUT; }
  168. (?i:int) { return HGT_INT; }
  169. (?i:noperspective) { return HGT_NOPERSPECTIVE; }
  170. (?i:out) { return HGT_OUT; }
  171. (?i:return) { return HGT_RETURN; }
  172. (?i:sampler1d) { return HGT_SAMPLER1D; }
  173. (?i:sampler2d) { return HGT_SAMPLER2D; }
  174. (?i:sampler3d) { return HGT_SAMPLER3D; }
  175. (?i:samplercube) { return HGT_SAMPLERCUBE; }
  176. (?i:struct) { return HGT_STRUCT; }
  177. (?i:switch) { return HGT_SWITCH; }
  178. (?i:uint) { return HGT_UINT; }
  179. (?i:uniform) { return HGT_UNIFORM; }
  180. (?i:void) { return HGT_VOID; }
  181. (?i:while) { return HGT_WHILE; }
  182. /*
  183. * HLSL keywords
  184. * Gathered from http://msdn.microsoft.com/en-us/library/windows/desktop/bb509568%28v=vs.85%29.aspx
  185. */
  186. (?i:appendstructuredbuffer) { return HT_APPENDSTRUCTUREDBUFFER; }
  187. (?i:asm) { return HT_ASM; }
  188. (?i:asm_fragment) { return HT_ASM_FRAGMENT; }
  189. (?i:blendstate) { return HT_BLENDSTATE; }
  190. (?i:buffer) { return HT_BUFFER; }
  191. (?i:byteaddressbuffer) { return HT_BYTEADDRESSBUFFER; }
  192. (?i:cbuffer) { return HT_CBUFFER; }
  193. (?i:column_major) { return HT_COLUMN_MAJOR; }
  194. (?i:compile) { return HT_COMPILE; }
  195. (?i:compile_fragment) { return HT_COMPILE_FRAGMENT; }
  196. (?i:compileshader) { return HT_COMPILESHADER; }
  197. (?i:computeshader) { return HT_COMPUTESHADER; }
  198. (?i:consumestructuredbuffer) { return HT_CONSUMESTRUCTUREDBUFFER; }
  199. (?i:depthstencilstate) { return HT_DEPTHSTENCILSTATE; }
  200. (?i:depthstencilview) { return HT_DEPTHSTENCILVIEW; }
  201. (?i:domainshader) { return HT_DOMAINSHADER; }
  202. (?i:dword) { return HT_DWORD; }
  203. (?i:extern) { return HT_EXTERN; }
  204. (?i:false) { return HT_FALSE; }
  205. (?i:fxgroup) { return HT_FXGROUP; }
  206. (?i:geometryshader) { return HT_GEOMETRYSHADER; }
  207. (?i:groupshared) { return HT_GROUPSHARED; }
  208. (?i:half) { return HT_HALF; }
  209. (?i:hullshader) { return HT_HULLSHADER; }
  210. (?i:inline) { return HT_INLINE; }
  211. (?i:inputpatch) { return HT_INPUTPATCH; }
  212. (?i:interface) { return HT_INTERFACE; }
  213. (?i:line) { return HT_LINE; }
  214. (?i:lineadj) { return HT_LINEADJ; }
  215. (?i:linear) { return HT_LINEAR; }
  216. (?i:linestream) { return HT_LINESTREAM; }
  217. (?i:matrix) { return HT_MATRIX; }
  218. (?i:namespace) { return HT_NAMESPACE; }
  219. (?i:nointerpolation) { return HT_NOINTERPOLATION; }
  220. (?i:null) { return HT_NULL; }
  221. (?i:outputpatch) { return HT_OUTPUTPATCH; }
  222. (?i:packoffset) { return HT_PACKOFFSET; }
  223. (?i:pass) { return HT_PASS; }
  224. (?i:pixelfragment) { return HT_PIXELFRAGMENT; }
  225. (?i:pixelshader) { return HT_PIXELSHADER; }
  226. (?i:point) { return HT_POINT; }
  227. (?i:pointstream) { return HT_POINTSTREAM; }
  228. (?i:precise) { return HT_PRECISE; }
  229. (?i:rasterizerstate) { return HT_RASTERIZERSTATE; }
  230. (?i:rendertargetview) { return HT_RENDERTARGETVIEW; }
  231. (?i:register) { return HT_REGISTER; }
  232. (?i:row_major) { return HT_ROW_MAJOR; }
  233. (?i:rwbuffer) { return HT_RWBUFFER; }
  234. (?i:rwbyteaddressbuffer) { return HT_RWBYTEADDRESSBUFFER; }
  235. (?i:rwstructuredbuffer) { return HT_RWSTRUCTUREDBUFFER; }
  236. (?i:rwtexture1d) { return HT_RWTEXTURE1D; }
  237. (?i:rwtexture1darray) { return HT_RWTEXTURE1DARRAY; }
  238. (?i:rwtexture2d) { return HT_RWTEXTURE2D; }
  239. (?i:rwtexture2darray) { return HT_RWTEXTURE2DARRAY; }
  240. (?i:rwtexture3d) { return HT_RWTEXTURE3D; }
  241. (?i:sampler) { return HT_SAMPLER; }
  242. (?i:sampler_state) { return HT_SAMPLER_STATE; }
  243. (?i:samplerstate) { return HT_SAMPLERSTATE; }
  244. (?i:samplercomparisonstate) { return HT_SAMPLERCOMPARISONSTATE; }
  245. (?i:shared) { return HT_SHARED; }
  246. (?i:snorm) { return HT_SNORM; }
  247. (?i:stateblock) { return HT_STATEBLOCK; }
  248. (?i:stateblock_state) { return HT_STATEBLOCK_STATE; }
  249. (?i:static) { return HT_STATIC; }
  250. (?i:string) { return HT_STRING; }
  251. (?i:structuredbuffer) { return HT_STRUCTUREDBUFFER; }
  252. (?i:tbuffer) { return HT_TBUFFER; }
  253. (?i:technique) { return HT_TECHNIQUE; }
  254. (?i:technique10) { return HT_TECHNIQUE10; }
  255. (?i:technique11xz) { return HT_TECHNIQUE11XZ; }
  256. "texture" { return HT_TEXTURE; }
  257. (?i:texture1d) { return HT_TEXTURE1D; }
  258. (?i:texture1darray) { return HT_TEXTURE1DARRAY; }
  259. (?i:texture2d) { return HT_TEXTURE2D; }
  260. (?i:texture2darray) { return HT_TEXTURE2DARRAY; }
  261. (?i:texture2dms) { return HT_TEXTURE2DMS; }
  262. (?i:texture2dmsarray) { return HT_TEXTURE2DMSARRAY; }
  263. (?i:texture3d) { return HT_TEXTURE3D; }
  264. (?i:texturecube) { return HT_TEXTURECUBE; }
  265. (?i:texturecubearray) { return HT_TEXTURECUBEARRAY; }
  266. (?i:true) { return HT_TRUE; }
  267. (?i:typedef) { return HT_TYPEDEF; }
  268. (?i:triangle) { return HT_TRIANGLE; }
  269. (?i:triangleadj) { return HT_TRIANGLEADJ; }
  270. (?i:trianglestream) { return HT_TRIANGLESTREAM; }
  271. (?i:unorm) { return HT_UNORM; }
  272. (?i:vector) { return HT_VECTOR; }
  273. (?i:vertexfragment) { return HT_VERTEXFRAGMENT; }
  274. (?i:vertexshader) { return HT_VERTEXSHADER; }
  275. (?i:volatile) { return HT_VOLATILE; }
  276. /*
  277. * HLSL vector types
  278. * TODO: this can probably be factored somehow
  279. */
  280. (?i:bool1) { return HT_BOOL1; }
  281. (?i:bool1x1) { return HT_BOOL1x1; }
  282. (?i:bool2x1) { return HT_BOOL2x1; }
  283. (?i:bool3x1) { return HT_BOOL3x1; }
  284. (?i:bool4x1) { return HT_BOOL4x1; }
  285. (?i:bool2) { return HT_BOOL2; }
  286. (?i:bool1x2) { return HT_BOOL1x2; }
  287. (?i:bool2x2) { return HT_BOOL2x2; }
  288. (?i:bool3x2) { return HT_BOOL3x2; }
  289. (?i:bool4x2) { return HT_BOOL4x2; }
  290. (?i:bool3) { return HT_BOOL3; }
  291. (?i:bool1x3) { return HT_BOOL1x3; }
  292. (?i:bool2x3) { return HT_BOOL2x3; }
  293. (?i:bool3x3) { return HT_BOOL3x3; }
  294. (?i:bool4x3) { return HT_BOOL4x3; }
  295. (?i:bool4) { return HT_BOOL4; }
  296. (?i:bool1x4) { return HT_BOOL1x4; }
  297. (?i:bool2x4) { return HT_BOOL2x4; }
  298. (?i:bool3x4) { return HT_BOOL3x4; }
  299. (?i:bool4x4) { return HT_BOOL4x4; }
  300. (?i:float1) { return HT_FLOAT1; }
  301. (?i:float1x1) { return HT_FLOAT1x1; }
  302. (?i:float2x1) { return HT_FLOAT2x1; }
  303. (?i:float3x1) { return HT_FLOAT3x1; }
  304. (?i:float4x1) { return HT_FLOAT4x1; }
  305. (?i:float2) { return HT_FLOAT2; }
  306. (?i:float1x2) { return HT_FLOAT1x2; }
  307. (?i:float2x2) { return HT_FLOAT2x2; }
  308. (?i:float3x2) { return HT_FLOAT3x2; }
  309. (?i:float4x2) { return HT_FLOAT4x2; }
  310. (?i:float3) { return HT_FLOAT3; }
  311. (?i:float1x3) { return HT_FLOAT1x3; }
  312. (?i:float2x3) { return HT_FLOAT2x3; }
  313. (?i:float3x3) { return HT_FLOAT3x3; }
  314. (?i:float4x3) { return HT_FLOAT4x3; }
  315. (?i:float4) { return HT_FLOAT4; }
  316. (?i:float1x4) { return HT_FLOAT1x4; }
  317. (?i:float2x4) { return HT_FLOAT2x4; }
  318. (?i:float3x4) { return HT_FLOAT3x4; }
  319. (?i:float4x4) { return HT_FLOAT4x4; }
  320. (?i:double1) { return HT_DOUBLE1; }
  321. (?i:double1x1) { return HT_DOUBLE1x1; }
  322. (?i:double2x1) { return HT_DOUBLE2x1; }
  323. (?i:double3x1) { return HT_DOUBLE3x1; }
  324. (?i:double4x1) { return HT_DOUBLE4x1; }
  325. (?i:double2) { return HT_DOUBLE2; }
  326. (?i:double1x2) { return HT_DOUBLE1x2; }
  327. (?i:double2x2) { return HT_DOUBLE2x2; }
  328. (?i:double3x2) { return HT_DOUBLE3x2; }
  329. (?i:double4x2) { return HT_DOUBLE4x2; }
  330. (?i:double3) { return HT_DOUBLE3; }
  331. (?i:double1x3) { return HT_DOUBLE1x3; }
  332. (?i:double2x3) { return HT_DOUBLE2x3; }
  333. (?i:double3x3) { return HT_DOUBLE3x3; }
  334. (?i:double4x3) { return HT_DOUBLE4x3; }
  335. (?i:double4) { return HT_DOUBLE4; }
  336. (?i:double1x4) { return HT_DOUBLE1x4; }
  337. (?i:double2x4) { return HT_DOUBLE2x4; }
  338. (?i:double3x4) { return HT_DOUBLE3x4; }
  339. (?i:double4x4) { return HT_DOUBLE4x4; }
  340. (?i:dword1) { return HT_DWORD1; }
  341. (?i:dword1x1) { return HT_DWORD1x1; }
  342. (?i:dword2x1) { return HT_DWORD2x1; }
  343. (?i:dword3x1) { return HT_DWORD3x1; }
  344. (?i:dword4x1) { return HT_DWORD4x1; }
  345. (?i:dword2) { return HT_DWORD2; }
  346. (?i:dword1x2) { return HT_DWORD1x2; }
  347. (?i:dword2x2) { return HT_DWORD2x2; }
  348. (?i:dword3x2) { return HT_DWORD3x2; }
  349. (?i:dword4x2) { return HT_DWORD4x2; }
  350. (?i:dword3) { return HT_DWORD3; }
  351. (?i:dword1x3) { return HT_DWORD1x3; }
  352. (?i:dword2x3) { return HT_DWORD2x3; }
  353. (?i:dword3x3) { return HT_DWORD3x3; }
  354. (?i:dword4x3) { return HT_DWORD4x3; }
  355. (?i:dword4) { return HT_DWORD4; }
  356. (?i:dword1x4) { return HT_DWORD1x4; }
  357. (?i:dword2x4) { return HT_DWORD2x4; }
  358. (?i:dword3x4) { return HT_DWORD3x4; }
  359. (?i:dword4x4) { return HT_DWORD4x4; }
  360. (?i:int1) { return HT_INT1; }
  361. (?i:int1x1) { return HT_INT1x1; }
  362. (?i:int2x1) { return HT_INT2x1; }
  363. (?i:int3x1) { return HT_INT3x1; }
  364. (?i:int4x1) { return HT_INT4x1; }
  365. (?i:int2) { return HT_INT2; }
  366. (?i:int1x2) { return HT_INT1x2; }
  367. (?i:int2x2) { return HT_INT2x2; }
  368. (?i:int3x2) { return HT_INT3x2; }
  369. (?i:int4x2) { return HT_INT4x2; }
  370. (?i:int3) { return HT_INT3; }
  371. (?i:int1x3) { return HT_INT1x3; }
  372. (?i:int2x3) { return HT_INT2x3; }
  373. (?i:int3x3) { return HT_INT3x3; }
  374. (?i:int4x3) { return HT_INT4x3; }
  375. (?i:int4) { return HT_INT4; }
  376. (?i:int1x4) { return HT_INT1x4; }
  377. (?i:int2x4) { return HT_INT2x4; }
  378. (?i:int3x4) { return HT_INT3x4; }
  379. (?i:int4x4) { return HT_INT4x4; }
  380. (?i:uint1) { return HT_UINT1; }
  381. (?i:uint1x1) { return HT_UINT1x1; }
  382. (?i:uint2x1) { return HT_UINT2x1; }
  383. (?i:uint3x1) { return HT_UINT3x1; }
  384. (?i:uint4x1) { return HT_UINT4x1; }
  385. (?i:uint2) { return HT_UINT2; }
  386. (?i:uint1x2) { return HT_UINT1x2; }
  387. (?i:uint2x2) { return HT_UINT2x2; }
  388. (?i:uint3x2) { return HT_UINT3x2; }
  389. (?i:uint4x2) { return HT_UINT4x2; }
  390. (?i:uint3) { return HT_UINT3; }
  391. (?i:uint1x3) { return HT_UINT1x3; }
  392. (?i:uint2x3) { return HT_UINT2x3; }
  393. (?i:uint3x3) { return HT_UINT3x3; }
  394. (?i:uint4x3) { return HT_UINT4x3; }
  395. (?i:uint4) { return HT_UINT4; }
  396. (?i:uint1x4) { return HT_UINT1x4; }
  397. (?i:uint2x4) { return HT_UINT2x4; }
  398. (?i:uint3x4) { return HT_UINT3x4; }
  399. (?i:uint4x4) { return HT_UINT4x4; }
  400. /*
  401. * HLSL preprocessor directives
  402. * Gathered from http://msdn.microsoft.com/en-us/library/windows/desktop/bb943993%28v=vs.85%29.aspx
  403. */
  404. "#"[ \t]*"define" { return PREPROCESSOR_DEFINE; }
  405. "#"[ \t]*"elif" { return PREPROCESSOR_ELIF; }
  406. "#"[ \t]*"else" { return PREPROCESSOR_ELSE; }
  407. "#"[ \t]*"endif" { return PREPROCESSOR_ENDIF; }
  408. "#"[ \t]*"error" { return PREPROCESSOR_ERROR; }
  409. "#"[ \t]*"if" { return PREPROCESSOR_IF; }
  410. "#"[ \t]*"ifdef" { return PREPROCESSOR_IFDEF; }
  411. "#"[ \t]*"ifndef" { return PREPROCESSOR_IFNDEF; }
  412. "#"[ \t]*"include" { return PREPROCESSOR_INCLUDE; }
  413. "#"[ \t]*"line" { return PREPROCESSOR_LINE; }
  414. "#"[ \t]*"pragma" { return PREPROCESSOR_PRAGMA; }
  415. "#"[ \t]*"undef" { return PREPROCESSOR_UNDEF; }
  416. /*
  417. * GLSL preprocessor directives
  418. */
  419. "#"[ \t]*"version".* { /* ignore for now */ }
  420. /*
  421. * LolFx preprocessor directives
  422. */
  423. "#"[ \t]*"region GLSL" { BEGIN(GLSL); }
  424. "#"[ \t]*"region HLSL" { BEGIN(HLSL); }
  425. "#"[ \t]*"pragma"[ \t]*"lolfx".* { /* ignore for now */ }
  426. /*
  427. * HLSL reserved keywords
  428. * Gathered from http://msdn.microsoft.com/en-us/library/windows/desktop/bb509569%28v=vs.85%29.aspx
  429. */
  430. (?i:auto) { return HT_AUTO; }
  431. (?i:catch) { return HT_CATCH; }
  432. (?i:char) { return HT_CHAR; }
  433. (?i:class) { return HT_CLASS; }
  434. (?i:const_cast) { return HT_CONST_CAST; }
  435. (?i:delete) { return HT_DELETE; }
  436. (?i:dynamic_cast) { return HT_DYNAMIC_CAST; }
  437. (?i:enum) { return HT_ENUM; }
  438. (?i:explicit) { return HT_EXPLICIT; }
  439. (?i:friend) { return HT_FRIEND; }
  440. (?i:goto) { return HT_GOTO; }
  441. (?i:long) { return HT_LONG; }
  442. (?i:mutable) { return HT_MUTABLE; }
  443. (?i:new) { return HT_NEW; }
  444. (?i:operator) { return HT_OPERATOR; }
  445. (?i:private) { return HT_PRIVATE; }
  446. (?i:protected) { return HT_PROTECTED; }
  447. (?i:public) { return HT_PUBLIC; }
  448. (?i:reinterpret_cast) { return HT_REINTERPRET_CAST; }
  449. (?i:short) { return HT_SHORT; }
  450. (?i:signed) { return HT_SIGNED; }
  451. (?i:sizeof) { return HT_SIZEOF; }
  452. (?i:static_cast) { return HT_STATIC_CAST; }
  453. (?i:template) { return HT_TEMPLATE; }
  454. (?i:this) { return HT_THIS; }
  455. (?i:throw) { return HT_THROW; }
  456. (?i:try) { return HT_TRY; }
  457. (?i:typename) { return HT_TYPENAME; }
  458. (?i:union) { return HT_UNION; }
  459. (?i:unsigned) { return HT_UNSIGNED; }
  460. (?i:using) { return HT_USING; }
  461. (?i:virtual) { return HT_VIRTUAL; }
  462. /*
  463. * Various tokens
  464. */
  465. "++" { return T_INC; }
  466. "--" { return T_DEC; }
  467. "<=" { return T_LE; }
  468. ">=" { return T_GE; }
  469. "==" { return T_EQ; }
  470. "!=" { return T_NE; }
  471. "<<" { return T_LEFT; }
  472. ">>" { return T_RIGHT; }
  473. "&&" { return T_AND; }
  474. "||" { return T_OR; }
  475. "^^" { return T_XOR; }
  476. "*=" { return T_MULEQ; }
  477. "/=" { return T_DIVEQ; }
  478. "%=" { return T_MODEQ; }
  479. "+=" { return T_ADDEQ; }
  480. "-=" { return T_SUBEQ; }
  481. "<<=" { return T_LEFTEQ; }
  482. ">>=" { return T_RIGHTEQ; }
  483. "&=" { return T_ANDEQ; }
  484. "^=" { return T_XOREQ; }
  485. "|=" { return T_OREQ; }
  486. (0|[1-9][0-9]*)\.[0-9]+ { yylval.fval = atof(yytext); return FLOATCONSTANT; }
  487. (0|[1-9][0-9]*)[uU] { yylval.uval = atoi(yytext); return UINTCONSTANT; }
  488. (0|[1-9][0-9]*) { yylval.ival = atoi(yytext); return INTCONSTANT; }
  489. [a-zA-Z][a-zA-Z0-9_]* {
  490. /* Copy token for now */
  491. yylval.sval = strdup(yytext);
  492. return IDENTIFIER;
  493. }
  494. [ \t\n]+ { /* ignore whitespace */ }
  495. . { return *yytext; }
  496. /*
  497. * Ignore C comments
  498. */
  499. <GLSL>"/*" { comment_caller = GLSL; BEGIN(C_COMMENT); }
  500. <HLSL>"/*" { comment_caller = HLSL; BEGIN(C_COMMENT); }
  501. "/*" { comment_caller = INITIAL; BEGIN(C_COMMENT); }
  502. <C_COMMENT>"*/" { BEGIN(comment_caller); }
  503. <C_COMMENT>[^*]* { }
  504. <C_COMMENT>. { }
  505. /*
  506. * Ignore C++ comments
  507. */
  508. <GLSL>"//" { comment_caller = GLSL; BEGIN(CPP_COMMENT); }
  509. <HLSL>"//" { comment_caller = HLSL; BEGIN(CPP_COMMENT); }
  510. "//" { comment_caller = INITIAL; BEGIN(CPP_COMMENT); }
  511. <CPP_COMMENT>\n { BEGIN(comment_caller); }
  512. <CPP_COMMENT>.* { }
  513. %%