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.
 
 
 

209 lines
7.2 KiB

  1. %{
  2. //
  3. // Lol Engine
  4. //
  5. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  6. // (c) 2009-2013 Cédric Lecacheur <jordx@free.fr>
  7. // (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  8. // This program is free software; you can redistribute it and/or
  9. // modify it under the terms of the Do What The Fuck You Want To
  10. // Public License, Version 2, as published by Sam Hocevar. See
  11. // 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 "core.h"
  22. #include "easymesh/easymesh-compiler.h"
  23. typedef lol::EasyMeshParser::token token;
  24. typedef lol::EasyMeshParser::token_type token_type;
  25. #ifndef YY_DECL
  26. # define YY_DECL lol::EasyMeshParser::token_type \
  27. lol::EasyMeshScanner::lex(lol::EasyMeshParser::semantic_type* yylval, \
  28. lol::EasyMeshParser::location_type* yylloc)
  29. #endif
  30. #define yyterminate() return token::T_END
  31. #define YY_NO_UNISTD_H
  32. #define YY_USER_ACTION yylloc->columns(yyleng);
  33. %}
  34. %option c++ prefix="EasyMesh"
  35. %option batch yywrap nounput stack
  36. %%
  37. %{ /* reset location at the beginning of yylex() */
  38. yylloc->step();
  39. %}
  40. (csgu|csgunion) { return token::T_CSGUNION; }
  41. (csgs|CsgSub) { return token::T_CSGSUBSTRACT; }
  42. (csgsl|CsgSubL) { return token::T_CSGSUBSTRACTLOSS; }
  43. (csga|csgand) { return token::T_CSGAND; }
  44. (csgx|csgxor) { return token::T_CSGXOR; }
  45. (lp|loop) { return token::T_LOOP; }
  46. (sc|setcolor) { return token::T_COLOR; }
  47. (sca|setcolora) { return token::T_ACOLOR; }
  48. (scb|setcolorb) { return token::T_BCOLOR; }
  49. (scv|setcolorv) { return token::T_VCOLOR; }
  50. (tsw|tglscalewind) { return token::T_TOGGLESCALEWINDING; }
  51. (tqw|tglquadweight) { return token::T_TOGGLEQUADWEIGHTING; }
  52. (tpbn|tglpstbuildnormal) { return token::T_TOGGLEPOSTBUILDNORMAL; }
  53. (tvnc|tglvertnocleanup) { return token::T_TOGGLEVERTNOCLEANUP; }
  54. (vm|vertmerge) { return token::T_VERTMERGE; }
  55. (vs|vertseparate) { return token::T_VERTSEPARATE; }
  56. (tx|translatex) { return token::T_TRANSLATEX; }
  57. (ty|translatey) { return token::T_TRANSLATEY; }
  58. (tz|translatez) { return token::T_TRANSLATEZ; }
  59. (t|translate) { return token::T_TRANSLATE; }
  60. (rx|rotatex) { return token::T_ROTATEX; }
  61. (ry|rotatey) { return token::T_ROTATEY; }
  62. (rz|rotatez) { return token::T_ROTATEZ; }
  63. (r|rotate) { return token::T_ROTATE; }
  64. (rj|radialjitter) { return token::T_RADIALJITTER; }
  65. (tax|taperx) { return token::T_TAPERX; }
  66. (tay|tapery) { return token::T_TAPERY; }
  67. (taz|taperz) { return token::T_TAPERZ; }
  68. (twx|twistx) { return token::T_TWISTX; }
  69. (twy|twisty) { return token::T_TWISTY; }
  70. (twz|twistz) { return token::T_TWISTZ; }
  71. (shx|shearx) { return token::T_SHEARX; }
  72. (shy|sheary) { return token::T_SHEARY; }
  73. (shz|shearz) { return token::T_SHEARZ; }
  74. (stx|stretchx) { return token::T_STRETCHX; }
  75. (sty|stretchy) { return token::T_STRETCHY; }
  76. (stz|stretchz) { return token::T_STRETCHZ; }
  77. (bdxy|bendxy) { return token::T_BENDXY; }
  78. (bdxz|bendxz) { return token::T_BENDXZ; }
  79. (bdyx|bendyx) { return token::T_BENDYX; }
  80. (bdyz|bendyz) { return token::T_BENDYZ; }
  81. (bdzx|bendzx) { return token::T_BENDZX; }
  82. (bdzy|bendzy) { return token::T_BENDZY; }
  83. (sx|scalex) { return token::T_SCALEX; }
  84. (sy|scaley) { return token::T_SCALEY; }
  85. (sz|scalez) { return token::T_SCALEZ; }
  86. (s|scale) { return token::T_SCALE; }
  87. (mx|mirrorx) { return token::T_MIRRORX; }
  88. (my|mirrory) { return token::T_MIRRORY; }
  89. (mz|mirrorz) { return token::T_MIRRORZ; }
  90. (ch|chamfer) { return token::T_CHAMFER; }
  91. (splt|splittriangle) { return token::T_SPLITTRIANGLE; }
  92. (smth|smooth) { return token::T_SMOOTHMESH; }
  93. (dup|duplicate) { return token::T_DUPLICATE; }
  94. (ac|addcylinder) { return token::T_CYLINDER; }
  95. (asph|addsphere) { return token::T_SPHERE; }
  96. (acap|addcapsule) { return token::T_CAPSULE; }
  97. (ato|addtorus) { return token::T_TORUS; }
  98. (ab|addbox) { return token::T_BOX; }
  99. (ascb|addsmoothchamfbox) { return token::T_SMOOTHCHAMFBOX; }
  100. (afcb|addflatchamfbox) { return token::T_FLATCHAMFBOX; }
  101. (as|addstar) { return token::T_STAR; }
  102. (aes|addexpandedstar) { return token::T_EXPANDEDSTAR; }
  103. (ad|adddisc) { return token::T_DISC; }
  104. (at|addtriangle) { return token::T_TRIANGLE; }
  105. (aq|addquad) { return token::T_QUAD; }
  106. (acg|addcog) { return token::T_COG; }
  107. %{ /* ======= BASE COLOR TYPES ========================================= */ %}
  108. %{ /* COLOR */ %}
  109. #[0-9a-fA-F]{3} {
  110. uint32_t tmp = std::strtol(yytext + 1, nullptr, 16);
  111. yylval->u32val = 0x11000000u * (tmp >> 8)
  112. | 0x00110000u * ((tmp >> 4) & 0xf)
  113. | 0x00001100u * (tmp & 0xf)
  114. | 0x000000ffu;
  115. return token::COLOR; }
  116. #[0-9a-fA-F]{4} {
  117. uint32_t tmp = std::strtol(yytext + 1, nullptr, 16);
  118. yylval->u32val = 0x11000000u * (tmp >> 12)
  119. | 0x00110000u * ((tmp >> 8) & 0xf)
  120. | 0x00001100u * ((tmp >> 4) & 0xf)
  121. | 0x00000011u * (tmp & 0xf);
  122. return token::COLOR; }
  123. #[0-9a-fA-F]{6} {
  124. yylval->u32val = 0xffu
  125. | 0x100u * (uint32_t)std::strtol(yytext + 1, nullptr, 16);
  126. return token::COLOR; }
  127. #[0-9a-fA-F]{8} {
  128. yylval->u32val = (uint32_t)std::strtol(yytext + 1, nullptr, 16);
  129. return token::COLOR; }
  130. %{ /* ======= BASE DATA TYPES ========================================= */ %}
  131. %{ /* BOOL */ %}
  132. true { yylval->bval = true; return token::BOOLEAN; }
  133. false { yylval->bval = false; return token::BOOLEAN; }
  134. %{ /* FLOAT */ %}
  135. [-+]?[0-9]*\.[0-9]+([eE][-+]?[0-9]+)? {
  136. yylval->fval = (float)std::atof(yytext); return token::F_NUMBER; }
  137. %{ /* INT */ %}
  138. [-+]?[0-9]+ {
  139. yylval->ival = std::atoi(yytext); return token::I_NUMBER; }
  140. %{ /* ======= COMMENTS ======= */ %}
  141. "//".* { /* ignore this */ }
  142. %{ /* Semantics tokens */ %}
  143. "-" { return token_type('-'); }
  144. "(" { return token_type('('); }
  145. ")" { return token_type(')'); }
  146. "{" { return token_type('{'); }
  147. "}" { return token_type('}'); }
  148. [\[] { return token_type('['); }
  149. [\]] { return token_type(']'); }
  150. [ ,] { /* ignore this */ }
  151. [\n] { /* ignore this */ }
  152. . { return token::T_ERROR; }
  153. %%
  154. lol::EasyMeshScanner::EasyMeshScanner(char const *command)
  155. : EasyMeshFlexLexer(0, 0),
  156. m_input(command)
  157. {
  158. }
  159. lol::EasyMeshScanner::~EasyMeshScanner()
  160. {
  161. }
  162. int lol::EasyMeshScanner::LexerInput(char* buf, int max_size)
  163. {
  164. (void)max_size; /* unused for now */
  165. buf[0] = m_input[0];
  166. if (buf[0])
  167. ++m_input;
  168. return buf[0] ? 1 : 0;
  169. }
  170. #ifdef yylex
  171. #undef yylex
  172. #endif
  173. int EasyMeshFlexLexer::yylex()
  174. {
  175. std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl;
  176. return 0;
  177. }
  178. int EasyMeshFlexLexer::yywrap()
  179. {
  180. return 1;
  181. }