lime_scan_tokens.l 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU Library General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. %{
  17. void out(char*t, char*v);
  18. void lit();
  19. void tok(char*t);
  20. void php();
  21. %}
  22. %option stack
  23. %option yylineno
  24. %option main
  25. %x code
  26. %x dquote
  27. %x squote
  28. CHAR \n|.
  29. ALPHA [a-zA-Z]
  30. DIGIT [0-9]
  31. ALNUM {ALPHA}|{DIGIT}
  32. WORD {ALNUM}|_
  33. STOP "."
  34. SYM {ALPHA}{WORD}*'*
  35. LIT '.'
  36. ESC "\"{CHAR}
  37. SCHAR [^\']|ESC
  38. DCHAR [^\"]|ESC
  39. COM "//"|"#"
  40. CC [^*\n]
  41. CX "*"+{CC}+
  42. CT "*"+"/"
  43. BLOCKCMT "/*"({CC}|{CX})*{CT}
  44. %x pragma
  45. %%
  46. [[:space:]]+ {}
  47. #.* {}
  48. {STOP} out("stop", ".");
  49. {SYM} tok("sym");
  50. {LIT} tok("lit");
  51. "/"{WORD}+ |
  52. "/$" out("lambda", yytext+1);
  53. "%"{WORD}+ {
  54. out("pragma", yytext+1);
  55. yy_push_state(pragma);
  56. }
  57. <*>"{" {
  58. lit();
  59. yy_push_state(code);
  60. }
  61. . lit();
  62. <pragma>{
  63. \n {
  64. out("stop", ".");
  65. yy_pop_state();
  66. }
  67. [[:space:]] {}
  68. {SYM} tok("sym");
  69. {LIT} tok("lit");
  70. . lit();
  71. }
  72. <code>{
  73. "}" {
  74. lit();
  75. yy_pop_state();
  76. }
  77. '{SCHAR}*' php();
  78. \"{DCHAR}*\" php();
  79. {COM}.* php();
  80. {BLOCKCMT} php();
  81. [^{}'"#/]+ php();
  82. . php();
  83. }
  84. %%
  85. void lit() {
  86. char lit[] = "'.'";
  87. lit[1] = *yytext;
  88. out(lit, yytext);
  89. }
  90. void tok(char*t) {
  91. out(t, yytext);
  92. }
  93. void php() {
  94. out("php", yytext);
  95. }
  96. void out(char*type, char*value) {
  97. printf("%d\001%s\001%s", yylineno, type, value);
  98. fputc(0, stdout);
  99. }