Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

lolfx-scanner.l 32 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. %{
  2. //
  3. // Lol Engine
  4. //
  5. // Copyright © 2012—2018 Sam Hocevar <sam@hocevar.net>
  6. //
  7. // Lol Engine is free software. It comes without any warranty, to
  8. // the extent permitted by applicable law. You can redistribute it
  9. // and/or modify it under the terms of the Do What the Fuck You Want
  10. // to Public License, Version 2, as published by the WTFPL Task Force.
  11. // See http://www.wtfpl.net/ for more details.
  12. //
  13. #if defined HAVE_CONFIG_H
  14. # include "config.h"
  15. #endif
  16. #include <cstdlib>
  17. using std::exit;
  18. using std::malloc;
  19. using std::realloc;
  20. using std::free;
  21. #include <iostream>
  22. #include <map>
  23. #include "core.h"
  24. #include "gpu/lolfx-compiler.h"
  25. typedef lol::LolFxParser::token token;
  26. typedef lol::LolFxParser::token_type token_type;
  27. #ifndef YY_DECL
  28. # define YY_DECL lol::LolFxParser::token_type \
  29. lol::LolFxScanner::lex(lol::LolFxParser::semantic_type* yylval, \
  30. lol::LolFxParser::location_type* yylloc)
  31. #endif
  32. #define yyterminate() return token::T_END
  33. #define YY_NO_UNISTD_H
  34. #define YY_USER_ACTION yylloc->columns(yyleng);
  35. %}
  36. %option c++ prefix="LolFx"
  37. %option batch yywrap nounput stack
  38. %x C_COMMENT
  39. %x CPP_COMMENT
  40. %x PREPROCESSOR_COMMENT
  41. %%
  42. %{
  43. /* reset location at the beginning of yylex() */
  44. yylloc->step();
  45. int language_guess = INITIAL;
  46. m_pp_stack.Push(BlockIsTrue);
  47. %}
  48. /*
  49. * GLSL keywords
  50. */
  51. "subroutine" { return token::GT_SUBROUTINE; }
  52. "patch" { return token::GT_PATCH; }
  53. "sample" { return token::GT_SAMPLE; }
  54. "flat" { return token::GT_FLAT; }
  55. "smooth" { return token::GT_SMOOTH; }
  56. "layout" { return token::GT_LAYOUT; }
  57. "sampler1dshadow" { return token::GT_SAMPLER1DSHADOW; }
  58. "sampler2dshadow" { return token::GT_SAMPLER2DSHADOW; }
  59. "samplercubeshadow" { return token::GT_SAMPLERCUBESHADOW; }
  60. "sampler1darray" { return token::GT_SAMPLER1DARRAY; }
  61. "sampler2darray" { return token::GT_SAMPLER2DARRAY; }
  62. "sampler1darrayshadow" { return token::GT_SAMPLER1DARRAYSHADOW; }
  63. "sampler2darrayshadow" { return token::GT_SAMPLER2DARRAYSHADOW; }
  64. "isampler1d" { return token::GT_ISAMPLER1D; }
  65. "isampler2d" { return token::GT_ISAMPLER2D; }
  66. "isampler3d" { return token::GT_ISAMPLER3D; }
  67. "isamplercube" { return token::GT_ISAMPLERCUBE; }
  68. "isampler1darray" { return token::GT_ISAMPLER1DARRAY; }
  69. "isampler2darray" { return token::GT_ISAMPLER2DARRAY; }
  70. "usampler1d" { return token::GT_USAMPLER1D; }
  71. "usampler2d" { return token::GT_USAMPLER2D; }
  72. "usampler3d" { return token::GT_USAMPLER3D; }
  73. "usamplercube" { return token::GT_USAMPLERCUBE; }
  74. "usampler1darray" { return token::GT_USAMPLER1DARRAY; }
  75. "usampler2darray" { return token::GT_USAMPLER2DARRAY; }
  76. "sampler2drect" { return token::GT_SAMPLER2DRECT; }
  77. "sampler2drectshadow" { return token::GT_SAMPLER2DRECTSHADOW; }
  78. "isampler2drect" { return token::GT_ISAMPLER2DRECT; }
  79. "usampler2drect" { return token::GT_USAMPLER2DRECT; }
  80. "samplerbuffer" { return token::GT_SAMPLERBUFFER; }
  81. "isamplerbuffer" { return token::GT_ISAMPLERBUFFER; }
  82. "usamplerbuffer" { return token::GT_USAMPLERBUFFER; }
  83. "samplercubearray" { return token::GT_SAMPLERCUBEARRAY; }
  84. "samplercubearrayshadow" { return token::GT_SAMPLERCUBEARRAYSHADOW; }
  85. "isamplercubearray" { return token::GT_ISAMPLERCUBEARRAY; }
  86. "usamplercubearray" { return token::GT_USAMPLERCUBEARRAY; }
  87. "sampler2dms" { return token::GT_SAMPLER2DMS; }
  88. "isampler2dms" { return token::GT_ISAMPLER2DMS; }
  89. "usampler2dms" { return token::GT_USAMPLER2DMS; }
  90. "sampler2dmsarray" { return token::GT_SAMPLER2DMSARRAY; }
  91. "isampler2dmsarray" { return token::GT_ISAMPLER2DMSARRAY; }
  92. "usampler2dmsarray" { return token::GT_USAMPLER2DMSARRAY; }
  93. "highp" { return token::GT_HIGHP; }
  94. "mediump" { return token::GT_MEDIUMP; }
  95. "lowp" { return token::GT_LOWP; }
  96. "precision" { return token::GT_PRECISION; }
  97. "invariant" { return token::GT_INVARIANT; }
  98. /*
  99. * Deprecated GLSL keywords
  100. */
  101. "attribute" { return token::GT_ATTRIBUTE; }
  102. "varying" { return token::GT_VARYING; }
  103. /*
  104. * GLSL vector types
  105. */
  106. "bvec2" { return token::GT_BVEC2; }
  107. "bvec3" { return token::GT_BVEC3; }
  108. "bvec4" { return token::GT_BVEC4; }
  109. "ivec2" { return token::GT_IVEC2; }
  110. "ivec3" { return token::GT_IVEC3; }
  111. "ivec4" { return token::GT_IVEC4; }
  112. "uvec2" { return token::GT_UVEC2; }
  113. "uvec3" { return token::GT_UVEC3; }
  114. "uvec4" { return token::GT_UVEC4; }
  115. "vec2" { return token::GT_VEC2; }
  116. "vec3" { return token::GT_VEC3; }
  117. "vec4" { return token::GT_VEC4; }
  118. "mat2" { return token::GT_MAT2; }
  119. "mat2x2" { return token::GT_MAT2X2; }
  120. "mat2x3" { return token::GT_MAT2X3; }
  121. "mat2x4" { return token::GT_MAT2X4; }
  122. "mat3" { return token::GT_MAT3; }
  123. "mat3x2" { return token::GT_MAT3X2; }
  124. "mat3x3" { return token::GT_MAT3X3; }
  125. "mat3x4" { return token::GT_MAT3X4; }
  126. "mat4" { return token::GT_MAT4; }
  127. "mat4x2" { return token::GT_MAT4X2; }
  128. "mat4x3" { return token::GT_MAT4X3; }
  129. "mat4x4" { return token::GT_MAT4X4; }
  130. "dvec2" { return token::GT_DVEC2; }
  131. "dvec3" { return token::GT_DVEC3; }
  132. "dvec4" { return token::GT_DVEC4; }
  133. "dmat2" { return token::GT_DMAT2; }
  134. "dmat2x2" { return token::GT_DMAT2X2; }
  135. "dmat2x3" { return token::GT_DMAT2X3; }
  136. "dmat2x4" { return token::GT_DMAT2X4; }
  137. "dmat3" { return token::GT_DMAT3; }
  138. "dmat3x2" { return token::GT_DMAT3X2; }
  139. "dmat3x3" { return token::GT_DMAT3X3; }
  140. "dmat3x4" { return token::GT_DMAT3X4; }
  141. "dmat4" { return token::GT_DMAT4; }
  142. "dmat4x2" { return token::GT_DMAT4X2; }
  143. "dmat4x3" { return token::GT_DMAT4X3; }
  144. "dmat4x4" { return token::GT_DMAT4X4; }
  145. /*
  146. * GLSL constant values
  147. */
  148. "true" { yylval->ival = 1; return token::BOOLCONSTANT; }
  149. "false" { yylval->ival = 0; return token::BOOLCONSTANT; }
  150. /*
  151. * GLSL keywords that are also valid or reserved in HLSL
  152. * and HLSL keywords that are also valid or reserved in GLSL.
  153. */
  154. "bool" { return token::GHT_BOOL; }
  155. "break" { return token::GHT_BREAK; }
  156. "case" { return token::GHT_CASE; }
  157. "centroid" { return token::GHT_CENTROID; }
  158. "const" { return token::GHT_CONST; }
  159. "continue" { return token::GHT_CONTINUE; }
  160. "default" { return token::GHT_DEFAULT; }
  161. "discard" { return token::GHT_DISCARD; }
  162. "do" { return token::GHT_DO; }
  163. "double" { return token::GHT_DOUBLE; }
  164. "else" { return token::GHT_ELSE; }
  165. "float" { return token::GHT_FLOAT; }
  166. "for" { return token::GHT_FOR; }
  167. "if" { return token::GHT_IF; }
  168. "in" { return token::GHT_IN; }
  169. "inout" { return token::GHT_INOUT; }
  170. "int" { return token::GHT_INT; }
  171. "noperspective" { return token::GHT_NOPERSPECTIVE; }
  172. "out" { return token::GHT_OUT; }
  173. "return" { return token::GHT_RETURN; }
  174. "sampler1d" { return token::GHT_SAMPLER1D; }
  175. "sampler2d" { return token::GHT_SAMPLER2D; }
  176. "sampler3d" { return token::GHT_SAMPLER3D; }
  177. "samplercube" { return token::GHT_SAMPLERCUBE; }
  178. "struct" { return token::GHT_STRUCT; }
  179. "switch" { return token::GHT_SWITCH; }
  180. "uint" { return token::GHT_UINT; }
  181. "uniform" { return token::GHT_UNIFORM; }
  182. "void" { return token::GHT_VOID; }
  183. "while" { return token::GHT_WHILE; }
  184. (?i:bool) { return token::HGT_BOOL; }
  185. (?i:break) { return token::HGT_BREAK; }
  186. (?i:case) { return token::HGT_CASE; }
  187. (?i:centroid) { return token::HGT_CENTROID; }
  188. (?i:const) { return token::HGT_CONST; }
  189. (?i:continue) { return token::HGT_CONTINUE; }
  190. (?i:default) { return token::HGT_DEFAULT; }
  191. (?i:discard) { return token::HGT_DISCARD; }
  192. (?i:do) { return token::HGT_DO; }
  193. (?i:double) { return token::HGT_DOUBLE; }
  194. (?i:else) { return token::HGT_ELSE; }
  195. (?i:float) { return token::HGT_FLOAT; }
  196. (?i:for) { return token::HGT_FOR; }
  197. (?i:if) { return token::HGT_IF; }
  198. (?i:in) { return token::HGT_IN; }
  199. (?i:inout) { return token::HGT_INOUT; }
  200. (?i:int) { return token::HGT_INT; }
  201. (?i:noperspective) { return token::HGT_NOPERSPECTIVE; }
  202. (?i:out) { return token::HGT_OUT; }
  203. (?i:return) { return token::HGT_RETURN; }
  204. (?i:sampler1d) { return token::HGT_SAMPLER1D; }
  205. (?i:sampler2d) { return token::HGT_SAMPLER2D; }
  206. (?i:sampler3d) { return token::HGT_SAMPLER3D; }
  207. (?i:samplercube) { return token::HGT_SAMPLERCUBE; }
  208. (?i:struct) { return token::HGT_STRUCT; }
  209. (?i:switch) { return token::HGT_SWITCH; }
  210. (?i:uint) { return token::HGT_UINT; }
  211. (?i:uniform) { return token::HGT_UNIFORM; }
  212. (?i:void) { return token::HGT_VOID; }
  213. (?i:while) { return token::HGT_WHILE; }
  214. /*
  215. * HLSL keywords
  216. * Gathered from http://msdn.microsoft.com/en-us/library/windows/desktop/bb509568%28v=vs.85%29.aspx
  217. */
  218. (?i:appendstructuredbuffer) { return token::HT_APPENDSTRUCTUREDBUFFER; }
  219. (?i:asm) { return token::HT_ASM; }
  220. (?i:asm_fragment) { return token::HT_ASM_FRAGMENT; }
  221. (?i:blendstate) { return token::HT_BLENDSTATE; }
  222. (?i:buffer) { return token::HT_BUFFER; }
  223. (?i:byteaddressbuffer) { return token::HT_BYTEADDRESSBUFFER; }
  224. (?i:cbuffer) { return token::HT_CBUFFER; }
  225. (?i:column_major) { return token::HT_COLUMN_MAJOR; }
  226. (?i:compile) { return token::HT_COMPILE; }
  227. (?i:compile_fragment) { return token::HT_COMPILE_FRAGMENT; }
  228. (?i:compileshader) { return token::HT_COMPILESHADER; }
  229. (?i:computeshader) { return token::HT_COMPUTESHADER; }
  230. (?i:consumestructuredbuffer) { return token::HT_CONSUMESTRUCTUREDBUFFER; }
  231. (?i:depthstencilstate) { return token::HT_DEPTHSTENCILSTATE; }
  232. (?i:depthstencilview) { return token::HT_DEPTHSTENCILVIEW; }
  233. (?i:domainshader) { return token::HT_DOMAINSHADER; }
  234. (?i:dword) { return token::HT_DWORD; }
  235. (?i:extern) { return token::HT_EXTERN; }
  236. (?i:false) { return token::HT_FALSE; }
  237. (?i:fxgroup) { return token::HT_FXGROUP; }
  238. (?i:geometryshader) { return token::HT_GEOMETRYSHADER; }
  239. (?i:groupshared) { return token::HT_GROUPSHARED; }
  240. (?i:half) { return token::HT_HALF; }
  241. (?i:hullshader) { return token::HT_HULLSHADER; }
  242. (?i:inline) { return token::HT_INLINE; }
  243. (?i:inputpatch) { return token::HT_INPUTPATCH; }
  244. (?i:interface) { return token::HT_INTERFACE; }
  245. (?i:line) { return token::HT_LINE; }
  246. (?i:lineadj) { return token::HT_LINEADJ; }
  247. (?i:linear) { return token::HT_LINEAR; }
  248. (?i:linestream) { return token::HT_LINESTREAM; }
  249. (?i:matrix) { return token::HT_MATRIX; }
  250. (?i:namespace) { return token::HT_NAMESPACE; }
  251. (?i:nointerpolation) { return token::HT_NOINTERPOLATION; }
  252. (?i:null) { return token::HT_NULL; }
  253. (?i:outputpatch) { return token::HT_OUTPUTPATCH; }
  254. (?i:packoffset) { return token::HT_PACKOFFSET; }
  255. (?i:pass) { return token::HT_PASS; }
  256. (?i:pixelfragment) { return token::HT_PIXELFRAGMENT; }
  257. (?i:pixelshader) { return token::HT_PIXELSHADER; }
  258. (?i:point) { return token::HT_POINT; }
  259. (?i:pointstream) { return token::HT_POINTSTREAM; }
  260. (?i:precise) { return token::HT_PRECISE; }
  261. (?i:rasterizerstate) { return token::HT_RASTERIZERSTATE; }
  262. (?i:rendertargetview) { return token::HT_RENDERTARGETVIEW; }
  263. (?i:register) { return token::HT_REGISTER; }
  264. (?i:row_major) { return token::HT_ROW_MAJOR; }
  265. (?i:rwbuffer) { return token::HT_RWBUFFER; }
  266. (?i:rwbyteaddressbuffer) { return token::HT_RWBYTEADDRESSBUFFER; }
  267. (?i:rwstructuredbuffer) { return token::HT_RWSTRUCTUREDBUFFER; }
  268. (?i:rwtexture1d) { return token::HT_RWTEXTURE1D; }
  269. (?i:rwtexture1darray) { return token::HT_RWTEXTURE1DARRAY; }
  270. (?i:rwtexture2d) { return token::HT_RWTEXTURE2D; }
  271. (?i:rwtexture2darray) { return token::HT_RWTEXTURE2DARRAY; }
  272. (?i:rwtexture3d) { return token::HT_RWTEXTURE3D; }
  273. (?i:sampler) { return token::HT_SAMPLER; }
  274. (?i:sampler_state) { return token::HT_SAMPLER_STATE; }
  275. (?i:samplerstate) { return token::HT_SAMPLERSTATE; }
  276. (?i:samplercomparisonstate) { return token::HT_SAMPLERCOMPARISONSTATE; }
  277. (?i:shared) { return token::HT_SHARED; }
  278. (?i:snorm) { return token::HT_SNORM; }
  279. (?i:stateblock) { return token::HT_STATEBLOCK; }
  280. (?i:stateblock_state) { return token::HT_STATEBLOCK_STATE; }
  281. (?i:static) { return token::HT_STATIC; }
  282. (?i:string) { return token::HT_STRING; }
  283. (?i:structuredbuffer) { return token::HT_STRUCTUREDBUFFER; }
  284. (?i:tbuffer) { return token::HT_TBUFFER; }
  285. (?i:technique) { return token::HT_TECHNIQUE; }
  286. (?i:technique10) { return token::HT_TECHNIQUE10; }
  287. (?i:technique11xz) { return token::HT_TECHNIQUE11XZ; }
  288. "texture" { return token::HT_TEXTURE; }
  289. (?i:texture1d) { return token::HT_TEXTURE1D; }
  290. (?i:texture1darray) { return token::HT_TEXTURE1DARRAY; }
  291. (?i:texture2d) { return token::HT_TEXTURE2D; }
  292. (?i:texture2darray) { return token::HT_TEXTURE2DARRAY; }
  293. (?i:texture2dms) { return token::HT_TEXTURE2DMS; }
  294. (?i:texture2dmsarray) { return token::HT_TEXTURE2DMSARRAY; }
  295. (?i:texture3d) { return token::HT_TEXTURE3D; }
  296. (?i:texturecube) { return token::HT_TEXTURECUBE; }
  297. (?i:texturecubearray) { return token::HT_TEXTURECUBEARRAY; }
  298. (?i:true) { return token::HT_TRUE; }
  299. (?i:typedef) { return token::HT_TYPEDEF; }
  300. (?i:triangle) { return token::HT_TRIANGLE; }
  301. (?i:triangleadj) { return token::HT_TRIANGLEADJ; }
  302. (?i:trianglestream) { return token::HT_TRIANGLESTREAM; }
  303. (?i:unorm) { return token::HT_UNORM; }
  304. (?i:vector) { return token::HT_VECTOR; }
  305. (?i:vertexfragment) { return token::HT_VERTEXFRAGMENT; }
  306. (?i:vertexshader) { return token::HT_VERTEXSHADER; }
  307. (?i:volatile) { return token::HT_VOLATILE; }
  308. /*
  309. * HLSL vector types
  310. * TODO: this can probably be factored somehow
  311. */
  312. (?i:bool1) { return token::HT_BOOL1; }
  313. (?i:bool1x1) { return token::HT_BOOL1x1; }
  314. (?i:bool2x1) { return token::HT_BOOL2x1; }
  315. (?i:bool3x1) { return token::HT_BOOL3x1; }
  316. (?i:bool4x1) { return token::HT_BOOL4x1; }
  317. (?i:bool2) { return token::HT_BOOL2; }
  318. (?i:bool1x2) { return token::HT_BOOL1x2; }
  319. (?i:bool2x2) { return token::HT_BOOL2x2; }
  320. (?i:bool3x2) { return token::HT_BOOL3x2; }
  321. (?i:bool4x2) { return token::HT_BOOL4x2; }
  322. (?i:bool3) { return token::HT_BOOL3; }
  323. (?i:bool1x3) { return token::HT_BOOL1x3; }
  324. (?i:bool2x3) { return token::HT_BOOL2x3; }
  325. (?i:bool3x3) { return token::HT_BOOL3x3; }
  326. (?i:bool4x3) { return token::HT_BOOL4x3; }
  327. (?i:bool4) { return token::HT_BOOL4; }
  328. (?i:bool1x4) { return token::HT_BOOL1x4; }
  329. (?i:bool2x4) { return token::HT_BOOL2x4; }
  330. (?i:bool3x4) { return token::HT_BOOL3x4; }
  331. (?i:bool4x4) { return token::HT_BOOL4x4; }
  332. (?i:float1) { return token::HT_FLOAT1; }
  333. (?i:float1x1) { return token::HT_FLOAT1x1; }
  334. (?i:float2x1) { return token::HT_FLOAT2x1; }
  335. (?i:float3x1) { return token::HT_FLOAT3x1; }
  336. (?i:float4x1) { return token::HT_FLOAT4x1; }
  337. (?i:float2) { return token::HT_FLOAT2; }
  338. (?i:float1x2) { return token::HT_FLOAT1x2; }
  339. (?i:float2x2) { return token::HT_FLOAT2x2; }
  340. (?i:float3x2) { return token::HT_FLOAT3x2; }
  341. (?i:float4x2) { return token::HT_FLOAT4x2; }
  342. (?i:float3) { return token::HT_FLOAT3; }
  343. (?i:float1x3) { return token::HT_FLOAT1x3; }
  344. (?i:float2x3) { return token::HT_FLOAT2x3; }
  345. (?i:float3x3) { return token::HT_FLOAT3x3; }
  346. (?i:float4x3) { return token::HT_FLOAT4x3; }
  347. (?i:float4) { return token::HT_FLOAT4; }
  348. (?i:float1x4) { return token::HT_FLOAT1x4; }
  349. (?i:float2x4) { return token::HT_FLOAT2x4; }
  350. (?i:float3x4) { return token::HT_FLOAT3x4; }
  351. (?i:float4x4) { return token::HT_FLOAT4x4; }
  352. (?i:double1) { return token::HT_DOUBLE1; }
  353. (?i:double1x1) { return token::HT_DOUBLE1x1; }
  354. (?i:double2x1) { return token::HT_DOUBLE2x1; }
  355. (?i:double3x1) { return token::HT_DOUBLE3x1; }
  356. (?i:double4x1) { return token::HT_DOUBLE4x1; }
  357. (?i:double2) { return token::HT_DOUBLE2; }
  358. (?i:double1x2) { return token::HT_DOUBLE1x2; }
  359. (?i:double2x2) { return token::HT_DOUBLE2x2; }
  360. (?i:double3x2) { return token::HT_DOUBLE3x2; }
  361. (?i:double4x2) { return token::HT_DOUBLE4x2; }
  362. (?i:double3) { return token::HT_DOUBLE3; }
  363. (?i:double1x3) { return token::HT_DOUBLE1x3; }
  364. (?i:double2x3) { return token::HT_DOUBLE2x3; }
  365. (?i:double3x3) { return token::HT_DOUBLE3x3; }
  366. (?i:double4x3) { return token::HT_DOUBLE4x3; }
  367. (?i:double4) { return token::HT_DOUBLE4; }
  368. (?i:double1x4) { return token::HT_DOUBLE1x4; }
  369. (?i:double2x4) { return token::HT_DOUBLE2x4; }
  370. (?i:double3x4) { return token::HT_DOUBLE3x4; }
  371. (?i:double4x4) { return token::HT_DOUBLE4x4; }
  372. (?i:dword1) { return token::HT_DWORD1; }
  373. (?i:dword1x1) { return token::HT_DWORD1x1; }
  374. (?i:dword2x1) { return token::HT_DWORD2x1; }
  375. (?i:dword3x1) { return token::HT_DWORD3x1; }
  376. (?i:dword4x1) { return token::HT_DWORD4x1; }
  377. (?i:dword2) { return token::HT_DWORD2; }
  378. (?i:dword1x2) { return token::HT_DWORD1x2; }
  379. (?i:dword2x2) { return token::HT_DWORD2x2; }
  380. (?i:dword3x2) { return token::HT_DWORD3x2; }
  381. (?i:dword4x2) { return token::HT_DWORD4x2; }
  382. (?i:dword3) { return token::HT_DWORD3; }
  383. (?i:dword1x3) { return token::HT_DWORD1x3; }
  384. (?i:dword2x3) { return token::HT_DWORD2x3; }
  385. (?i:dword3x3) { return token::HT_DWORD3x3; }
  386. (?i:dword4x3) { return token::HT_DWORD4x3; }
  387. (?i:dword4) { return token::HT_DWORD4; }
  388. (?i:dword1x4) { return token::HT_DWORD1x4; }
  389. (?i:dword2x4) { return token::HT_DWORD2x4; }
  390. (?i:dword3x4) { return token::HT_DWORD3x4; }
  391. (?i:dword4x4) { return token::HT_DWORD4x4; }
  392. (?i:int1) { return token::HT_INT1; }
  393. (?i:int1x1) { return token::HT_INT1x1; }
  394. (?i:int2x1) { return token::HT_INT2x1; }
  395. (?i:int3x1) { return token::HT_INT3x1; }
  396. (?i:int4x1) { return token::HT_INT4x1; }
  397. (?i:int2) { return token::HT_INT2; }
  398. (?i:int1x2) { return token::HT_INT1x2; }
  399. (?i:int2x2) { return token::HT_INT2x2; }
  400. (?i:int3x2) { return token::HT_INT3x2; }
  401. (?i:int4x2) { return token::HT_INT4x2; }
  402. (?i:int3) { return token::HT_INT3; }
  403. (?i:int1x3) { return token::HT_INT1x3; }
  404. (?i:int2x3) { return token::HT_INT2x3; }
  405. (?i:int3x3) { return token::HT_INT3x3; }
  406. (?i:int4x3) { return token::HT_INT4x3; }
  407. (?i:int4) { return token::HT_INT4; }
  408. (?i:int1x4) { return token::HT_INT1x4; }
  409. (?i:int2x4) { return token::HT_INT2x4; }
  410. (?i:int3x4) { return token::HT_INT3x4; }
  411. (?i:int4x4) { return token::HT_INT4x4; }
  412. (?i:uint1) { return token::HT_UINT1; }
  413. (?i:uint1x1) { return token::HT_UINT1x1; }
  414. (?i:uint2x1) { return token::HT_UINT2x1; }
  415. (?i:uint3x1) { return token::HT_UINT3x1; }
  416. (?i:uint4x1) { return token::HT_UINT4x1; }
  417. (?i:uint2) { return token::HT_UINT2; }
  418. (?i:uint1x2) { return token::HT_UINT1x2; }
  419. (?i:uint2x2) { return token::HT_UINT2x2; }
  420. (?i:uint3x2) { return token::HT_UINT3x2; }
  421. (?i:uint4x2) { return token::HT_UINT4x2; }
  422. (?i:uint3) { return token::HT_UINT3; }
  423. (?i:uint1x3) { return token::HT_UINT1x3; }
  424. (?i:uint2x3) { return token::HT_UINT2x3; }
  425. (?i:uint3x3) { return token::HT_UINT3x3; }
  426. (?i:uint4x3) { return token::HT_UINT4x3; }
  427. (?i:uint4) { return token::HT_UINT4; }
  428. (?i:uint1x4) { return token::HT_UINT1x4; }
  429. (?i:uint2x4) { return token::HT_UINT2x4; }
  430. (?i:uint3x4) { return token::HT_UINT3x4; }
  431. (?i:uint4x4) { return token::HT_UINT4x4; }
  432. /*
  433. * HLSL preprocessor directives
  434. * Gathered from http://msdn.microsoft.com/en-us/library/windows/desktop/bb943993%28v=vs.85%29.aspx
  435. */
  436. ^[ \t]*"#"[ \t]*"define".* {
  437. /* FIXME: this is very, very limited */
  438. char const *tmp = strstr(yytext, "define") + 6;
  439. while (*tmp == ' ' || *tmp == '\n')
  440. tmp++;
  441. if (*tmp == '\0')
  442. return token::PREPROCESSOR_DEFINE;
  443. char const *tmp2 = tmp;
  444. while (*tmp != ' ' && *tmp != '\n' && *tmp != '\0')
  445. tmp++;
  446. String key(tmp2, (int)(tmp - tmp2));
  447. while (*tmp == ' ' || *tmp == '\n')
  448. tmp++;
  449. String val(*tmp ? tmp : "1");
  450. Log::Debug("new macro: ‘%s’ = ‘%s’\n", key.C(), val.C());
  451. m_pp_defines[key] = val;
  452. }
  453. ^[ \t]*"#"[ \t]*"elif" {
  454. if (m_pp_stack.Count() <= 1)
  455. return token::PREPROCESSOR_ELIF;
  456. m_pp_stack.Last() = BlockIsForeverFalse;
  457. BEGIN(PREPROCESSOR_COMMENT);
  458. }
  459. ^[ \t]*"#"[ \t]*"else" {
  460. if (m_pp_stack.Count() <= 1)
  461. return token::PREPROCESSOR_ELSE;
  462. m_pp_stack.Last() = BlockIsForeverFalse;
  463. BEGIN(PREPROCESSOR_COMMENT);
  464. }
  465. ^[ \t]*"#"[ \t]*"endif" {
  466. if (m_pp_stack.Count() <= 1)
  467. return token::PREPROCESSOR_ENDIF;
  468. m_pp_stack.Pop();
  469. }
  470. ^[ \t]*"#"[ \t]*"error".* { return token::PREPROCESSOR_ERROR; }
  471. ^[ \t]*"#"[ \t]*"if".* {
  472. if (IsExpressionTrue(strstr(yytext, "if") + 2))
  473. {
  474. m_pp_stack.Push(BlockIsTrue);
  475. }
  476. else
  477. {
  478. m_pp_stack.Push(BlockIsFalse);
  479. BEGIN(PREPROCESSOR_COMMENT);
  480. }
  481. }
  482. ^[ \t]*"#"[ \t]*"ifdef" {
  483. /* FIXME: this is very, very limited */
  484. char const *tmp = strstr(yytext, "ifdef") + 5;
  485. while (*tmp == ' ' || *tmp == '\n')
  486. tmp++;
  487. if (*tmp == '\0')
  488. return token::PREPROCESSOR_IFDEF;
  489. char const *tmp2 = tmp;
  490. while (*tmp != ' ' && *tmp != '\n' && *tmp != '\0')
  491. tmp++;
  492. String key(tmp2, (int)(tmp - tmp2));
  493. if (has_key(m_pp_defines, key))
  494. {
  495. m_pp_stack.Push(BlockIsTrue);
  496. }
  497. else
  498. {
  499. m_pp_stack.Push(BlockIsFalse);
  500. BEGIN(PREPROCESSOR_COMMENT);
  501. }
  502. }
  503. ^[ \t]*"#"[ \t]*"ifndef" {
  504. /* FIXME: this is very, very limited */
  505. char const *tmp = strstr(yytext, "ifndef") + 6;
  506. while (*tmp == ' ' || *tmp == '\n')
  507. tmp++;
  508. if (*tmp == '\0')
  509. return token::PREPROCESSOR_IFDEF;
  510. char const *tmp2 = tmp;
  511. while (*tmp != ' ' && *tmp != '\n' && *tmp != '\0')
  512. tmp++;
  513. String key(tmp2, (int)(tmp - tmp2));
  514. if (has_key(m_pp_defines, key))
  515. {
  516. m_pp_stack.Push(BlockIsFalse);
  517. BEGIN(PREPROCESSOR_COMMENT);
  518. }
  519. else
  520. {
  521. m_pp_stack.Push(BlockIsTrue);
  522. }
  523. }
  524. ^[ \t]*"#"[ \t]*"include" { return token::PREPROCESSOR_INCLUDE; }
  525. ^[ \t]*"#"[ \t]*"line".* { /* ignore for now */ }
  526. ^[ \t]*"#"[ \t]*"pragma".* { /* ignore for now */ }
  527. ^[ \t]*"#"[ \t]*"undef" {
  528. /* FIXME: this is very, very limited */
  529. char const *tmp = strstr(yytext, "undef") + 5;
  530. while (*tmp == ' ' || *tmp == '\n')
  531. tmp++;
  532. if (*tmp == '\0')
  533. return token::PREPROCESSOR_UNDEF;
  534. char const *tmp2 = tmp;
  535. while (*tmp != ' ' && *tmp != '\n' && *tmp != '\0')
  536. tmp++;
  537. String key(tmp2, (int)(tmp - tmp2));
  538. Log::Debug("undef macro: ‘%s’\n", key.C());
  539. m_pp_defines.remove(key);
  540. }
  541. <PREPROCESSOR_COMMENT>^[ \t]*"#"[ \t]*(if|ifdef|ifndef)[ \t]+.*$ {
  542. m_pp_stack.Push(BlockIsForeverFalse);
  543. }
  544. <PREPROCESSOR_COMMENT>^[ \t]*"#"[ \t]*"else" {
  545. switch (m_pp_stack.Last())
  546. {
  547. case BlockIsFalse:
  548. m_pp_stack.Last() = BlockIsTrue;
  549. BEGIN(INITIAL);
  550. break;
  551. case BlockIsForeverFalse:
  552. break;
  553. case BlockIsTrue:
  554. m_pp_stack.Last() = BlockIsForeverFalse;
  555. break;
  556. }
  557. }
  558. <PREPROCESSOR_COMMENT>^[ \t]*"#"[ \t]*"elif" {
  559. switch (m_pp_stack.Last())
  560. {
  561. case BlockIsFalse:
  562. if (IsExpressionTrue(strstr(yytext, "elif") + 4))
  563. {
  564. m_pp_stack.Last() = BlockIsTrue;
  565. BEGIN(INITIAL);
  566. }
  567. break;
  568. case BlockIsForeverFalse:
  569. break;
  570. case BlockIsTrue:
  571. m_pp_stack.Last() = BlockIsForeverFalse;
  572. break;
  573. }
  574. }
  575. <PREPROCESSOR_COMMENT>^[ \t]*"#"[ \t]*"endif" {
  576. m_pp_stack.Pop();
  577. if (m_pp_stack.Last() == BlockIsTrue)
  578. BEGIN(INITIAL);
  579. }
  580. <PREPROCESSOR_COMMENT>\n { yylloc->lines(1); }
  581. <PREPROCESSOR_COMMENT>[^/#]* { }
  582. <PREPROCESSOR_COMMENT>"/*" { BEGIN(C_COMMENT); }
  583. <PREPROCESSOR_COMMENT>[/#] { }
  584. /*
  585. * GLSL preprocessor directives
  586. */
  587. ^[ \t]*"#"[ \t]*"version"[^\n]* { /* ignore for now */ }
  588. /*
  589. * HLSL reserved keywords
  590. * Gathered from http://msdn.microsoft.com/en-us/library/windows/desktop/bb509569%28v=vs.85%29.aspx
  591. */
  592. (?i:auto) { return token::HT_AUTO; }
  593. (?i:catch) { return token::HT_CATCH; }
  594. (?i:char) { return token::HT_CHAR; }
  595. (?i:class) { return token::HT_CLASS; }
  596. (?i:const_cast) { return token::HT_CONST_CAST; }
  597. (?i:delete) { return token::HT_DELETE; }
  598. (?i:dynamic_cast) { return token::HT_DYNAMIC_CAST; }
  599. (?i:enum) { return token::HT_ENUM; }
  600. (?i:explicit) { return token::HT_EXPLICIT; }
  601. (?i:friend) { return token::HT_FRIEND; }
  602. (?i:goto) { return token::HT_GOTO; }
  603. (?i:long) { return token::HT_LONG; }
  604. (?i:mutable) { return token::HT_MUTABLE; }
  605. (?i:new) { return token::HT_NEW; }
  606. (?i:operator) { return token::HT_OPERATOR; }
  607. (?i:private) { return token::HT_PRIVATE; }
  608. (?i:protected) { return token::HT_PROTECTED; }
  609. (?i:public) { return token::HT_PUBLIC; }
  610. (?i:reinterpret_cast) { return token::HT_REINTERPRET_CAST; }
  611. (?i:short) { return token::HT_SHORT; }
  612. (?i:signed) { return token::HT_SIGNED; }
  613. (?i:sizeof) { return token::HT_SIZEOF; }
  614. (?i:static_cast) { return token::HT_STATIC_CAST; }
  615. (?i:template) { return token::HT_TEMPLATE; }
  616. (?i:this) { return token::HT_THIS; }
  617. (?i:throw) { return token::HT_THROW; }
  618. (?i:try) { return token::HT_TRY; }
  619. (?i:typename) { return token::HT_TYPENAME; }
  620. (?i:union) { return token::HT_UNION; }
  621. (?i:unsigned) { return token::HT_UNSIGNED; }
  622. (?i:using) { return token::HT_USING; }
  623. (?i:virtual) { return token::HT_VIRTUAL; }
  624. /*
  625. * Various tokens
  626. */
  627. "++" { return token::T_INC; }
  628. "--" { return token::T_DEC; }
  629. "<=" { return token::T_LE; }
  630. ">=" { return token::T_GE; }
  631. "==" { return token::T_EQ; }
  632. "!=" { return token::T_NE; }
  633. "<<" { return token::T_LEFT; }
  634. ">>" { return token::T_RIGHT; }
  635. "&&" { return token::T_AND; }
  636. "||" { return token::T_OR; }
  637. "^^" { return token::T_XOR; }
  638. "*=" { return token::T_MULEQ; }
  639. "/=" { return token::T_DIVEQ; }
  640. "%=" { return token::T_MODEQ; }
  641. "+=" { return token::T_ADDEQ; }
  642. "-=" { return token::T_SUBEQ; }
  643. "<<=" { return token::T_LEFTEQ; }
  644. ">>=" { return token::T_RIGHTEQ; }
  645. "&=" { return token::T_ANDEQ; }
  646. "^=" { return token::T_XOREQ; }
  647. "|=" { return token::T_OREQ; }
  648. (0|[1-9][0-9]*)\.[0-9]+ {
  649. yylval->fval = std::atof(yytext);
  650. return token::FLOATCONSTANT;
  651. }
  652. (0|[1-9][0-9]*)[uU] {
  653. yylval->uval = std::atoi(yytext);
  654. return token::UINTCONSTANT;
  655. }
  656. (0|[1-9][0-9]*) {
  657. yylval->ival = std::atoi(yytext);
  658. return token::INTCONSTANT;
  659. }
  660. ([xyzw]{1,4}|[rgba]{1,4}|[stpq]{1,4}) {
  661. /* Copy token for now */
  662. yylval->sval = strdup(yytext);
  663. return token::FIELDSELECTION;
  664. }
  665. [a-zA-Z_][a-zA-Z0-9_]* {
  666. /* Copy token for now */
  667. yylval->sval = strdup(yytext);
  668. return token::IDENTIFIER;
  669. }
  670. [ \t\r]+ { /* ignore whitespace */ }
  671. [\n] { yylloc->lines(1); }
  672. . { return (token_type)*yytext; /* accept all characters */ }
  673. /*
  674. * Ignore C comments
  675. */
  676. "/*" { BEGIN(C_COMMENT); }
  677. <C_COMMENT>[^*\n]* { }
  678. <C_COMMENT>\n { yylloc->lines(1); }
  679. <C_COMMENT>. { }
  680. <C_COMMENT>"*/" {
  681. if (m_pp_stack.Last() == BlockIsTrue)
  682. BEGIN(INITIAL);
  683. else
  684. BEGIN(PREPROCESSOR_COMMENT);
  685. }
  686. /*
  687. * Ignore C++ comments
  688. */
  689. "//" { BEGIN(CPP_COMMENT); }
  690. <CPP_COMMENT>\n { yylloc->lines(1); BEGIN(INITIAL); }
  691. <CPP_COMMENT>.* { }
  692. %%
  693. lol::LolFxScanner::LolFxScanner(char const *command)
  694. : LolFxFlexLexer(0, 0),
  695. m_input(command)
  696. {
  697. }
  698. lol::LolFxScanner::~LolFxScanner()
  699. {
  700. }
  701. int lol::LolFxScanner::LexerInput(char* buf, int max_size)
  702. {
  703. buf[0] = m_input[0];
  704. if (buf[0])
  705. ++m_input;
  706. return buf[0] ? 1 : 0;
  707. }
  708. bool lol::LolFxScanner::IsExpressionTrue(char const *buf)
  709. {
  710. /* FIXME: this is really too limited */
  711. return std::atoi(buf) != 0;
  712. }
  713. #ifdef yylex
  714. #undef yylex
  715. #endif
  716. int LolFxFlexLexer::yylex()
  717. {
  718. std::cerr << "in LolFxFlexLexer::yylex() !" << std::endl;
  719. return 0;
  720. }
  721. int LolFxFlexLexer::yywrap()
  722. {
  723. return 1;
  724. }