miralang.l 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. %{
  2. /* This file is part of the software similarity tester SIM.
  3. Written by Dick Grune, Vrije Universiteit, Amsterdam.
  4. $Id: miralang.l,v 1.3 2007/08/29 09:10:34 dick Exp $
  5. */
  6. /*
  7. Miranda language front end for the similarity tester.
  8. Author: Emma Norling ([email protected])
  9. Date: Nov 1998
  10. */
  11. #include "language.h"
  12. #include "token.h"
  13. #include "lex.h"
  14. #include "lang.h"
  15. /* Language-dependent Code */
  16. #include "idf.h"
  17. static const struct idf reserved[] = {
  18. {"abstype", NORM('a')},
  19. {"bool", NORM('b')},
  20. {"char", NORM('c')},
  21. {"const", META('c')},
  22. {"div", NORM('d')},
  23. {"False", NORM('F')},
  24. {"if", NORM('i')},
  25. {"mod", NORM('m')},
  26. {"num", NORM('n')},
  27. {"otherwise", NORM('o')},
  28. {"readvals", NORM('r')},
  29. {"show", NORM('s')},
  30. {"sys_message", META('s')},
  31. {"True", NORM('T')},
  32. {"type", NORM('t')},
  33. {"where", NORM('w')},
  34. {"with", META('w')}
  35. };
  36. /* Token sets for module algollike */
  37. const TOKEN NonFinals[] = {
  38. NORM('('),
  39. NORM('['),
  40. NORM('='),
  41. NOTOKEN
  42. };
  43. const TOKEN NonInitials[] = {
  44. NORM(')'),
  45. NORM(']'),
  46. NOTOKEN
  47. };
  48. const TOKEN Openers[] = {
  49. NORM('('),
  50. NORM('['),
  51. NORM('='),
  52. NOTOKEN
  53. };
  54. const TOKEN Closers[] = {
  55. NORM(')'),
  56. NORM(']'),
  57. NOTOKEN
  58. };
  59. %}
  60. %option nounput
  61. %option never-interactive
  62. %Start Comment
  63. Layout ([ \t\r\f])
  64. ASCII95 ([- !"#$%&'()*+,./0-9:;<=>?@A-Z\[\\\]^_`a-z{|}~])
  65. AnyQuoted (\\.)
  66. StrChar ([^"\n\\]|{AnyQuoted})
  67. ChrChar ([^'\\]|{AnyQuoted})
  68. Idf ([A-Za-z][A-Za-z0-9_']*)
  69. %%
  70. "||".*$ { /* comment */
  71. }
  72. \"{StrChar}*\" { /* strings */
  73. return_ch('"');
  74. }
  75. \'{ChrChar}\' { /* characters */
  76. return_ch('\'');
  77. }
  78. \%{Layout}*include.* { /* skip %include line */
  79. }
  80. \%{Layout}*insert.* { /* skip %insert line */
  81. }
  82. {Idf} { /* identifier */
  83. return_tk(idf_in_list(yytext, reserved, sizeof reserved, IDF));
  84. }
  85. \n { /* count newlines */
  86. return_eol();
  87. }
  88. {Layout} { /* ignore layout */
  89. }
  90. {ASCII95} { /* copy other text */
  91. return_ch(yytext[0]);
  92. }
  93. . { /* count non-ASCII chars */
  94. lex_non_ascii_cnt++;
  95. }
  96. %%
  97. /* Language-INdependent Code */
  98. void
  99. yystart(void) {
  100. BEGIN INITIAL;
  101. }
  102. int
  103. yywrap(void) {
  104. return 1;
  105. }