lexer.l 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* =============================================================================
  2. //
  3. // This file is part of the qlow compiler.
  4. //
  5. // Copyright (C) 2014-2015 Nicolas Winkler
  6. //
  7. // This program is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. // ===========================================================================*/
  21. %{
  22. #include "Ast.h"
  23. //#define yylval qlow_parser_lval
  24. #define SET_TOKEN(t) (yylval.token = t)
  25. #define SET_STRING (yylval.string = new std::string(yytext, yyleng))
  26. extern "C" int yywrap()
  27. {
  28. return 1; /* do not continue on EOF */
  29. }
  30. %}
  31. %option prefix="qlow_parser_"
  32. %%
  33. [a-zA-Z_][a-zA-Z0-9_]* SET_STRING; return IDENTIFIER;
  34. . printf("Unknown token!\n"); yyterminate();
  35. %%
  36. /*
  37. [\t ] ; // Space or tab ignored
  38. \/\*[.\n]*\*\/ ; // comment
  39. \n return SET_TOKEN(NEW_LINE);
  40. ":" return SET_TOKEN(COLON);
  41. "," return SET_TOKEN(COMMA);
  42. ":=" return SET_TOKEN(ASSIGN);
  43. "." return SET_TOKEN(DOT);
  44. "+" return SET_TOKEN(PLUS);
  45. "-" return SET_TOKEN(MINUS);
  46. "*" return SET_TOKEN(ASTERISK);
  47. "/" return SET_TOKEN(SLASH);
  48. "(" return SET_TOKEN(ROUND_LEFT);
  49. ")" return SET_TOKEN(ROUND_RIGHT);
  50. "class" return SET_TOKEN(CLASS);
  51. "do" return SET_TOKEN(DO);
  52. "end" return SET_TOKEN(END);
  53. "if" return SET_TOKEN(IF);
  54. */