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.

153 lines
4.1 KiB

  1. %{
  2. //
  3. // Lol Engine
  4. //
  5. // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
  6. // (c) 2009-2012 Cédric Lecacheur <jordx@free.fr>
  7. // (c) 2009-2012 Benjamin 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://sam.zoy.org/projects/COPYING.WTFPL 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. mx { return token::T_MIRRORX; }
  59. my { return token::T_MIRRORY; }
  60. mz { return token::T_MIRRORZ; }
  61. ac { return token::T_CYLINDER; }
  62. ab { return token::T_BOX; }
  63. ascb { return token::T_SMOOTHCHAMFBOX; }
  64. afcb { return token::T_FLATCHAMFBOX; }
  65. acap { return token::T_CAPSULE; }
  66. asph { return token::T_SPHERE; }
  67. at { return token::T_TORUS; }
  68. as { return token::T_STAR; }
  69. aes { return token::T_EXPANDEDSTAR; }
  70. ad { return token::T_DISC; }
  71. at { return token::T_TRIANGLE; }
  72. aq { return token::T_QUAD; }
  73. acg { return token::T_COG; }
  74. #[0-9a-fA-F]{3} {
  75. uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
  76. yylval->u32val = 0x11000000u * (tmp >> 8)
  77. | 0x00110000u * ((tmp >> 4) & 0xf)
  78. | 0x00001100u * (tmp & 0xf)
  79. | 0x000000ffu;
  80. return token::COLOR; }
  81. #[0-9a-fA-F]{4} {
  82. uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
  83. yylval->u32val = 0x11000000u * (tmp >> 12)
  84. | 0x00110000u * ((tmp >> 8) & 0xf)
  85. | 0x00001100u * ((tmp >> 4) & 0xf)
  86. | 0x00000011u * (tmp & 0xf);
  87. return token::COLOR; }
  88. #[0-9a-fA-F]{6} {
  89. yylval->u32val = 0xffu
  90. | 0x100u * (uint32_t)std::strtol(yytext + 1, NULL, 16);
  91. return token::COLOR; }
  92. #[0-9a-fA-F]{8} {
  93. yylval->u32val = (uint32_t)std::strtol(yytext + 1, NULL, 16);
  94. return token::COLOR; }
  95. [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? {
  96. yylval->fval = std::atof(yytext); return token::NUMBER; }
  97. - { return token_type('-'); }
  98. "[" { return token_type('['); }
  99. "]" { return token_type(']'); }
  100. [ ,] { /* ignore this */ }
  101. [\n] { /* ignore this */ }
  102. . { return token::T_ERROR; }
  103. %%
  104. lol::EasyMeshScanner::EasyMeshScanner(char const *command)
  105. : EasyMeshFlexLexer(0, 0),
  106. m_input(command)
  107. {
  108. }
  109. lol::EasyMeshScanner::~EasyMeshScanner()
  110. {
  111. }
  112. int lol::EasyMeshScanner::LexerInput(char* buf, int max_size)
  113. {
  114. (void)max_size; /* unused for now */
  115. buf[0] = m_input[0];
  116. if (buf[0])
  117. ++m_input;
  118. return buf[0] ? 1 : 0;
  119. }
  120. #ifdef yylex
  121. #undef yylex
  122. #endif
  123. int EasyMeshFlexLexer::yylex()
  124. {
  125. std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl;
  126. return 0;
  127. }
  128. int EasyMeshFlexLexer::yywrap()
  129. {
  130. return 1;
  131. }