scan.l 2.9 KB

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