scan.l 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. %{
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. #include "emlookup.h"
  7. #include "subr.h"
  8. #include "error.h"
  9. #include "hall.h"
  10. #include "coerc.h"
  11. #include "extern.h"
  12. /* fileno is not C89 and can be missing sometimes. */
  13. #ifdef __LINUX__
  14. int fileno(FILE *stream);
  15. #endif
  16. int lineno=1;
  17. extern char *filename;
  18. #undef yywrap
  19. %}
  20. %%
  21. "/*" { char c;
  22. c = input(); if (c=='\n') lineno++;
  23. do {
  24. while (c!='*') {
  25. c = input();
  26. if (c=='\n') lineno++;
  27. }
  28. c = input();
  29. if (c=='\n') lineno++;
  30. } while (c!='/');
  31. }
  32. ^\#(line)?[ \t]*[0-9]+[ \t]+\".*\".*$ {
  33. int ind,ind2;
  34. for (ind=0; yytext[ind] < '0' || yytext[ind]>'9'; ind++)
  35. ;
  36. lineno=atoi(&yytext[ind])-1;
  37. for(;yytext[ind]!='"';ind++)
  38. ;
  39. for(ind2=ind+1;yytext[ind2]!='"';ind2++)
  40. ;
  41. yytext[ind2]=0;
  42. if (strcmp(yytext+ind+1,filename)!=0)
  43. filename=mystrcpy(yytext+ind+1);
  44. }
  45. "==" return(CMPEQ);
  46. "!=" return(CMPNE);
  47. "<" return(CMPLT);
  48. "<=" return(CMPLE);
  49. ">" return(CMPGT);
  50. ">=" return(CMPGE);
  51. "||" return(OR2);
  52. "&&" return(AND2);
  53. "<<" return(LSHIFT);
  54. ">>" return(RSHIFT);
  55. "!" return(NOT);
  56. "~" return(COMP);
  57. ":ro" { yylval.yy_int = AD_RO; return(ADORNACCESS); }
  58. ":wo" { yylval.yy_int = AD_WO; return(ADORNACCESS); }
  59. ":rw" { yylval.yy_int = AD_RW; return(ADORNACCESS); }
  60. ":cc" { yylval.yy_int = AD_CC; return(ADORNCC); }
  61. \$[0-9]+ { yylval.yy_int = atoi(yytext+1); return(DOLLAR); }
  62. \%[0-9]+ { yylval.yy_int = atoi(yytext+1); return(PERCENT); }
  63. \%[a-z] { yylval.yy_int = yytext[1]-'a'; return(ALLREG); }
  64. [0-9]+|0x[0-9A-Fa-f]+ { yylval.yy_int = myatoi(yytext); return(NUMBER); }
  65. [_A-Za-z][_A-Za-z0-9]* { register symbol *sy_p;
  66. if (yyleng==3 &&
  67. emhere &&
  68. (yylval.yy_int=mlookup(yytext))!=0) {
  69. return(EMMNEM);
  70. }
  71. if ((sy_p=lookup(yytext,symkeyw,justlooking))!=0)
  72. return(sy_p->sy_value.syv_keywno);
  73. yylval.yy_str = mystrcpy(yytext); return(IDENT);
  74. }
  75. \%[_A-Za-z][_A-Za-z0-9]* { yylval.yy_str = mystrcpy(yytext+1);
  76. return(PERC_IDENT);
  77. }
  78. \"[^"\n]*\" { yytext[yyleng-1]=0;
  79. yylval.yy_str = mystrcpy(yytext+1);
  80. return(STRING);
  81. }
  82. [0-9][bf] { yytext[2]=0;
  83. yylval.yy_str = mystrcpy(yytext);
  84. return(STRING);
  85. }
  86. \n { lineno++; }
  87. [ \t]* ;
  88. . return(yytext[0]);
  89. %%
  90. int skipping=0;
  91. int yywrap()
  92. {
  93. if (skipping)
  94. fatal("EOF reached during error recovery");
  95. return(1);
  96. }
  97. /* unput isn't technically legal in this section, so we need the
  98. * following definition to make it work. */
  99. #define yytext_ptr yytext
  100. void skipupto(int tok, char *str)
  101. {
  102. int i;
  103. skipping=1;
  104. while (yylex()!=tok)
  105. ;
  106. for(i=strlen(str); i>0; i--)
  107. unput(str[i-1]);
  108. skipping=0;
  109. }