Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

150 wiersze
4.2 KiB

  1. %{
  2. //
  3. // Lol Engine
  4. //
  5. // Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  6. // (c) 2013 Sam Hocevar <sam@hocevar.net>
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the Do What The Fuck You Want To
  9. // Public License, Version 2, as published by Sam Hocevar. See
  10. // http://www.wtfpl.net/ for more details.
  11. //
  12. #if defined HAVE_CONFIG_H
  13. # include "config.h"
  14. #endif
  15. #include <cstdlib>
  16. using std::exit;
  17. using std::malloc;
  18. using std::realloc;
  19. using std::free;
  20. #include "core.h"
  21. #include "../scenesetup.h"
  22. #include "../scenesetup-compiler.h"
  23. typedef lol::SceneSetupParser::token token;
  24. typedef lol::SceneSetupParser::token_type token_type;
  25. #ifndef YY_DECL
  26. # define YY_DECL lol::SceneSetupParser::token_type \
  27. lol::SceneSetupScanner::lex(lol::SceneSetupParser::semantic_type* yylval, \
  28. lol::SceneSetupParser::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="SceneSetup"
  35. %option batch yywrap nounput stack
  36. %%
  37. %{ /* reset location at the beginning of yylex() */
  38. yylloc->step();
  39. %}
  40. addlight { return token::T_ADDLIGHT; }
  41. position { return token::T_OBJPOSITION; }
  42. lookat { return token::T_OBJLOOKAT; }
  43. color { return token::T_OBJCOLOR; }
  44. clearcolor { return token::T_CLEARCOLOR; }
  45. showgizmo { return token::T_SHOWGIZMO; }
  46. showlight { return token::T_SHOWLIGHT; }
  47. custom { return token::T_CUSTOMCMD; }
  48. custom { return token::T_CUSTOMCMD; }
  49. %{ /* ======= BASE COLOR TYPES ========================================= */ %}
  50. %{ /* COLOR */ %}
  51. #[0-9a-fA-F]{3} {
  52. uint32_t tmp = std::strtol(yytext + 1, nullptr, 16);
  53. yylval->u32val = 0x11000000u * (tmp >> 8)
  54. | 0x00110000u * ((tmp >> 4) & 0xf)
  55. | 0x00001100u * (tmp & 0xf)
  56. | 0x000000ffu;
  57. return token::COLOR; }
  58. #[0-9a-fA-F]{4} {
  59. uint32_t tmp = std::strtol(yytext + 1, nullptr, 16);
  60. yylval->u32val = 0x11000000u * (tmp >> 12)
  61. | 0x00110000u * ((tmp >> 8) & 0xf)
  62. | 0x00001100u * ((tmp >> 4) & 0xf)
  63. | 0x00000011u * (tmp & 0xf);
  64. return token::COLOR; }
  65. #[0-9a-fA-F]{6} {
  66. yylval->u32val = 0xffu
  67. | 0x100u * (uint32_t)std::strtol(yytext + 1, nullptr, 16);
  68. return token::COLOR; }
  69. #[0-9a-fA-F]{8} {
  70. yylval->u32val = (uint32_t)std::strtol(yytext + 1, nullptr, 16);
  71. return token::COLOR; }
  72. %{ /* ======= BASE DATA TYPES ========================================= */ %}
  73. %{ /* BOOL */ %}
  74. true { yylval->bval = true; return token::BOOLEAN; }
  75. false { yylval->bval = false; return token::BOOLEAN; }
  76. %{ /* FLOAT */ %}
  77. [-+]?[0-9]*\.[0-9]+([eE][-+]?[0-9]+)? {
  78. yylval->fval = (float)std::atof(yytext); return token::F_NUMBER; }
  79. %{ /* INT */ %}
  80. [-+]?[0-9]+ {
  81. yylval->ival = std::atoi(yytext); return token::I_NUMBER; }
  82. %{ /* STRING */ %}
  83. [\"][^\"]*[\"] {
  84. yylval->sval = strdup(yytext); return token::STRING; }
  85. %{ /* STRING VAR */ %}
  86. [a-zA-Z][a-zA-Z_\-]+ {
  87. yylval->svval = strdup(yytext); return token::STRING_VAR; }
  88. %{ /* ======= COMMENTS ======= */ %}
  89. "//".* { /* ignore this */ }
  90. %{ /* Semantics tokens */ %}
  91. "-" { return token_type('-'); }
  92. "(" { return token_type('('); }
  93. ")" { return token_type(')'); }
  94. [ ,] { /* ignore this */ }
  95. [\n] { /* ignore this */ }
  96. . { return token::T_ERROR; }
  97. %%
  98. lol::SceneSetupScanner::SceneSetupScanner(char const *command)
  99. : SceneSetupFlexLexer(0, 0),
  100. m_input(command)
  101. {
  102. }
  103. lol::SceneSetupScanner::~SceneSetupScanner()
  104. {
  105. }
  106. int lol::SceneSetupScanner::LexerInput(char* buf, int max_size)
  107. {
  108. (void)max_size; /* unused for now */
  109. buf[0] = m_input[0];
  110. if (buf[0])
  111. ++m_input;
  112. return buf[0] ? 1 : 0;
  113. }
  114. #ifdef yylex
  115. #undef yylex
  116. #endif
  117. int SceneSetupFlexLexer::yylex()
  118. {
  119. std::cerr << "in SceneSetupFlexLexer::yylex() !" << std::endl;
  120. return 0;
  121. }
  122. int SceneSetupFlexLexer::yywrap()
  123. {
  124. return 1;
  125. }