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.
 
 
 

159 lines
4.3 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. %{
  38. /* reset location at the beginning of yylex() */
  39. yylloc->step();
  40. %}
  41. sc { return token::T_COLOR; }
  42. scb { return token::T_BGCOLOR; }
  43. ch { return token::T_CHAMFER; }
  44. tx { return token::T_TRANSLATEX; }
  45. ty { return token::T_TRANSLATEY; }
  46. tz { return token::T_TRANSLATEZ; }
  47. t { return token::T_TRANSLATE; }
  48. rx { return token::T_ROTATEX; }
  49. ry { return token::T_ROTATEY; }
  50. rz { return token::T_ROTATEZ; }
  51. tax { return token::T_TAPERX; }
  52. tay { return token::T_TAPERY; }
  53. taz { return token::T_TAPERZ; }
  54. sx { return token::T_SCALEX; }
  55. sy { return token::T_SCALEY; }
  56. sz { return token::T_SCALEZ; }
  57. s { return token::T_SCALE; }
  58. tsw { return token::T_TOGGLESCALEWINDING; }
  59. mx { return token::T_MIRRORX; }
  60. my { return token::T_MIRRORY; }
  61. mz { return token::T_MIRRORZ; }
  62. csgu { return token::T_CSGUNION; }
  63. csgs { return token::T_CSGSUBSTRACT; }
  64. csga { return token::T_CSGAND; }
  65. csgx { return token::T_CSGXOR; }
  66. ab { return token::T_BOX; }
  67. ac { return token::T_CYLINDER; }
  68. acap { return token::T_CAPSULE; }
  69. acg { return token::T_COG; }
  70. ad { return token::T_DISC; }
  71. aes { return token::T_EXPANDEDSTAR; }
  72. afcb { return token::T_FLATCHAMFBOX; }
  73. aq { return token::T_QUAD; }
  74. as { return token::T_STAR; }
  75. ascb { return token::T_SMOOTHCHAMFBOX; }
  76. asph { return token::T_SPHERE; }
  77. at { return token::T_TRIANGLE; }
  78. ato { return token::T_TORUS; }
  79. #[0-9a-fA-F]{3} {
  80. uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
  81. yylval->u32val = 0x11000000u * (tmp >> 8)
  82. | 0x00110000u * ((tmp >> 4) & 0xf)
  83. | 0x00001100u * (tmp & 0xf)
  84. | 0x000000ffu;
  85. return token::COLOR; }
  86. #[0-9a-fA-F]{4} {
  87. uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
  88. yylval->u32val = 0x11000000u * (tmp >> 12)
  89. | 0x00110000u * ((tmp >> 8) & 0xf)
  90. | 0x00001100u * ((tmp >> 4) & 0xf)
  91. | 0x00000011u * (tmp & 0xf);
  92. return token::COLOR; }
  93. #[0-9a-fA-F]{6} {
  94. yylval->u32val = 0xffu
  95. | 0x100u * (uint32_t)std::strtol(yytext + 1, NULL, 16);
  96. return token::COLOR; }
  97. #[0-9a-fA-F]{8} {
  98. yylval->u32val = (uint32_t)std::strtol(yytext + 1, NULL, 16);
  99. return token::COLOR; }
  100. [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? {
  101. yylval->fval = std::atof(yytext); return token::NUMBER; }
  102. - { return token_type('-'); }
  103. "[" { return token_type('['); }
  104. "]" { return token_type(']'); }
  105. [ ,] { /* ignore this */ }
  106. [\n] { /* ignore this */ }
  107. . { return token::T_ERROR; }
  108. %%
  109. lol::EasyMeshScanner::EasyMeshScanner(char const *command)
  110. : EasyMeshFlexLexer(0, 0),
  111. m_input(command)
  112. {
  113. }
  114. lol::EasyMeshScanner::~EasyMeshScanner()
  115. {
  116. }
  117. int lol::EasyMeshScanner::LexerInput(char* buf, int max_size)
  118. {
  119. (void)max_size; /* unused for now */
  120. buf[0] = m_input[0];
  121. if (buf[0])
  122. ++m_input;
  123. return buf[0] ? 1 : 0;
  124. }
  125. #ifdef yylex
  126. #undef yylex
  127. #endif
  128. int EasyMeshFlexLexer::yylex()
  129. {
  130. std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl;
  131. return 0;
  132. }
  133. int EasyMeshFlexLexer::yywrap()
  134. {
  135. return 1;
  136. }