No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

146 líneas
4.0 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. custom { return token::T_CUSTOMCMD; }
  46. %{ /* ======= BASE COLOR TYPES ========================================= */ %}
  47. %{ /* COLOR */ %}
  48. #[0-9a-fA-F]{3} {
  49. uint32_t tmp = std::strtol(yytext + 1, nullptr, 16);
  50. yylval->u32val = 0x11000000u * (tmp >> 8)
  51. | 0x00110000u * ((tmp >> 4) & 0xf)
  52. | 0x00001100u * (tmp & 0xf)
  53. | 0x000000ffu;
  54. return token::COLOR; }
  55. #[0-9a-fA-F]{4} {
  56. uint32_t tmp = std::strtol(yytext + 1, nullptr, 16);
  57. yylval->u32val = 0x11000000u * (tmp >> 12)
  58. | 0x00110000u * ((tmp >> 8) & 0xf)
  59. | 0x00001100u * ((tmp >> 4) & 0xf)
  60. | 0x00000011u * (tmp & 0xf);
  61. return token::COLOR; }
  62. #[0-9a-fA-F]{6} {
  63. yylval->u32val = 0xffu
  64. | 0x100u * (uint32_t)std::strtol(yytext + 1, nullptr, 16);
  65. return token::COLOR; }
  66. #[0-9a-fA-F]{8} {
  67. yylval->u32val = (uint32_t)std::strtol(yytext + 1, nullptr, 16);
  68. return token::COLOR; }
  69. %{ /* ======= BASE DATA TYPES ========================================= */ %}
  70. %{ /* BOOL */ %}
  71. true { yylval->bval = true; return token::BOOLEAN; }
  72. false { yylval->bval = false; return token::BOOLEAN; }
  73. %{ /* FLOAT */ %}
  74. [-+]?[0-9]*\.[0-9]+([eE][-+]?[0-9]+)? {
  75. yylval->fval = (float)std::atof(yytext); return token::F_NUMBER; }
  76. %{ /* INT */ %}
  77. [-+]?[0-9]+ {
  78. yylval->ival = std::atoi(yytext); return token::I_NUMBER; }
  79. %{ /* STRING */ %}
  80. [\"][^\"]*[\"] {
  81. yylval->sval = strdup(yytext); return token::STRING; }
  82. %{ /* STRING VAR */ %}
  83. [a-zA-Z][a-zA-Z_\-]+ {
  84. yylval->svval = strdup(yytext); return token::STRING_VAR; }
  85. %{ /* ======= COMMENTS ======= */ %}
  86. "//".* { /* ignore this */ }
  87. %{ /* Semantics tokens */ %}
  88. "-" { return token_type('-'); }
  89. "(" { return token_type('('); }
  90. ")" { return token_type(')'); }
  91. [ ,] { /* ignore this */ }
  92. [\n] { /* ignore this */ }
  93. . { return token::T_ERROR; }
  94. %%
  95. lol::SceneSetupScanner::SceneSetupScanner(char const *command)
  96. : SceneSetupFlexLexer(0, 0),
  97. m_input(command)
  98. {
  99. }
  100. lol::SceneSetupScanner::~SceneSetupScanner()
  101. {
  102. }
  103. int lol::SceneSetupScanner::LexerInput(char* buf, int max_size)
  104. {
  105. (void)max_size; /* unused for now */
  106. buf[0] = m_input[0];
  107. if (buf[0])
  108. ++m_input;
  109. return buf[0] ? 1 : 0;
  110. }
  111. #ifdef yylex
  112. #undef yylex
  113. #endif
  114. int SceneSetupFlexLexer::yylex()
  115. {
  116. std::cerr << "in SceneSetupFlexLexer::yylex() !" << std::endl;
  117. return 0;
  118. }
  119. int SceneSetupFlexLexer::yywrap()
  120. {
  121. return 1;
  122. }