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.
 
 
 

143 line
3.9 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 "core.h"
  17. #include "easymesh/easymesh-compiler.h"
  18. typedef lol::EasyMeshParser::token token;
  19. typedef lol::EasyMeshParser::token_type token_type;
  20. #ifndef YY_DECL
  21. # define YY_DECL lol::EasyMeshParser::token_type \
  22. lol::EasyMeshScanner::lex(lol::EasyMeshParser::semantic_type* yylval, \
  23. lol::EasyMeshParser::location_type* yylloc)
  24. #endif
  25. #define yyterminate() return token::T_END
  26. #define YY_NO_UNISTD_H
  27. #define YY_USER_ACTION yylloc->columns(yyleng);
  28. %}
  29. %option c++ prefix="EasyMesh"
  30. %option batch yywrap nounput stack
  31. %%
  32. %{
  33. /* reset location at the beginning of yylex() */
  34. yylloc->step();
  35. %}
  36. sc { return token::T_COLOR; }
  37. scb { return token::T_BGCOLOR; }
  38. ch { return token::T_CHAMFER; }
  39. tx { return token::T_TRANSLATEX; }
  40. ty { return token::T_TRANSLATEY; }
  41. tz { return token::T_TRANSLATEZ; }
  42. t { return token::T_TRANSLATE; }
  43. rx { return token::T_ROTATEX; }
  44. ry { return token::T_ROTATEY; }
  45. rz { return token::T_ROTATEZ; }
  46. tax { return token::T_TAPERX; }
  47. tay { return token::T_TAPERY; }
  48. taz { return token::T_TAPERZ; }
  49. sx { return token::T_SCALEX; }
  50. sy { return token::T_SCALEY; }
  51. sz { return token::T_SCALEZ; }
  52. s { return token::T_SCALE; }
  53. mx { return token::T_MIRRORX; }
  54. my { return token::T_MIRRORY; }
  55. mz { return token::T_MIRRORZ; }
  56. ac { return token::T_CYLINDER; }
  57. ab { return token::T_BOX; }
  58. ascb { return token::T_SMOOTHCHAMFBOX; }
  59. afcb { return token::T_FLATCHAMFBOX; }
  60. asph { return token::T_SPHERE; }
  61. as { return token::T_STAR; }
  62. aes { return token::T_EXPANDEDSTAR; }
  63. ad { return token::T_DISC; }
  64. at { return token::T_TRIANGLE; }
  65. aq { return token::T_QUAD; }
  66. acg { return token::T_COG; }
  67. #[0-9a-f]{3} {
  68. uint32_t tmp = strtol(yytext + 1, NULL, 16);
  69. yylval->u32val = 0x11000000u * (tmp >> 8)
  70. | 0x00110000u * ((tmp >> 4) & 0xf)
  71. | 0x00001100u * (tmp & 0xf)
  72. | 0x000000ffu;
  73. return token::COLOR; }
  74. #[0-9a-f]{4} {
  75. uint32_t tmp = strtol(yytext + 1, NULL, 16);
  76. yylval->u32val = 0x11000000u * (tmp >> 12)
  77. | 0x00110000u * ((tmp >> 8) & 0xf)
  78. | 0x00001100u * ((tmp >> 4) & 0xf)
  79. | 0x00000011u * (tmp & 0xf);
  80. return token::COLOR; }
  81. #[0-9a-f]{6} {
  82. yylval->u32val = 0xffu
  83. | 0x100u * (uint32_t)strtol(yytext + 1, NULL, 16);
  84. return token::COLOR; }
  85. #[0-9a-f]{8} {
  86. yylval->u32val = (uint32_t)strtol(yytext + 1, NULL, 16);
  87. return token::COLOR; }
  88. [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? {
  89. yylval->fval = atof(yytext); return token::NUMBER; }
  90. - { return token_type('-'); }
  91. "[" { return token_type('['); }
  92. "]" { return token_type(']'); }
  93. [ ,] { /* ignore this */ }
  94. [\n] { /* ignore this */ }
  95. . { return token::T_ERROR; }
  96. %%
  97. lol::EasyMeshScanner::EasyMeshScanner(char const *command)
  98. : EasyMeshFlexLexer(0, 0),
  99. m_input(command)
  100. {
  101. }
  102. lol::EasyMeshScanner::~EasyMeshScanner()
  103. {
  104. }
  105. int lol::EasyMeshScanner::LexerInput(char* buf, int max_size)
  106. {
  107. buf[0] = m_input[0];
  108. if (buf[0])
  109. ++m_input;
  110. return buf[0] ? 1 : 0;
  111. }
  112. #ifdef yylex
  113. #undef yylex
  114. #endif
  115. int EasyMeshFlexLexer::yylex()
  116. {
  117. std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl;
  118. return 0;
  119. }
  120. int EasyMeshFlexLexer::yywrap()
  121. {
  122. return 1;
  123. }