lua.lex 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. %{
  2. char *rcs_lualex = "$Id: $";
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "opcode.h"
  6. #include "hash.h"
  7. #include "inout.h"
  8. #include "table.h"
  9. #include "y.tab.h"
  10. #undef input
  11. #undef unput
  12. static Input input;
  13. static Unput unput;
  14. void lua_setinput (Input fn)
  15. {
  16. input = fn;
  17. }
  18. void lua_setunput (Unput fn)
  19. {
  20. unput = fn;
  21. }
  22. char *lua_lasttext (void)
  23. {
  24. return yytext;
  25. }
  26. %}
  27. %%
  28. [ \t]* ;
  29. ^"$debug" {yylval.vInt = 1; return DEBUG;}
  30. ^"$nodebug" {yylval.vInt = 0; return DEBUG;}
  31. \n lua_linenumber++;
  32. "--".* ;
  33. "local" return LOCAL;
  34. "if" return IF;
  35. "then" return THEN;
  36. "else" return ELSE;
  37. "elseif" return ELSEIF;
  38. "while" return WHILE;
  39. "do" return DO;
  40. "repeat" return REPEAT;
  41. "until" return UNTIL;
  42. "function" {
  43. yylval.vWord = lua_nfile-1;
  44. return FUNCTION;
  45. }
  46. "end" return END;
  47. "return" return RETURN;
  48. "local" return LOCAL;
  49. "nil" return NIL;
  50. "and" return AND;
  51. "or" return OR;
  52. "not" return NOT;
  53. "~=" return NE;
  54. "<=" return LE;
  55. ">=" return GE;
  56. ".." return CONC;
  57. \"[^\"]*\" |
  58. \'[^\']*\' {
  59. yylval.vWord = lua_findenclosedconstant (yytext);
  60. return STRING;
  61. }
  62. [0-9]+("."[0-9]*)? |
  63. ([0-9]+)?"."[0-9]+ |
  64. [0-9]+("."[0-9]*)?[dDeEgG][+-]?[0-9]+ |
  65. ([0-9]+)?"."[0-9]+[dDeEgG][+-]?[0-9]+ {
  66. yylval.vFloat = atof(yytext);
  67. return NUMBER;
  68. }
  69. [a-zA-Z_][a-zA-Z0-9_]* {
  70. yylval.vWord = lua_findsymbol (yytext);
  71. return NAME;
  72. }
  73. . return *yytext;