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