scan.l 3.0 KB

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