bootlex.l 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. %{
  2. #ifndef NORCSID
  3. static char rcsid2[]="$Id$";
  4. #endif
  5. /*
  6. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  7. * See the copyright notice in the ACK home directory, in the file "Copyright".
  8. *
  9. * Author: Hans van Staveren
  10. */
  11. #define MAXBACKUP 50
  12. #include <stdio.h>
  13. #include <assert.h>
  14. #include <em_spec.h>
  15. #include <em_flag.h>
  16. #include <em_reg.h>
  17. #include "booth.h"
  18. #include "y.tab.h"
  19. int lineno = 1;
  20. extern char *iname;
  21. extern char *scopy();
  22. %}
  23. %p 2000
  24. %%
  25. "/*" { char c;
  26. c = input();
  27. do {
  28. while (c!='*')
  29. c = input();
  30. c = input();
  31. } while (c!='/');
  32. }
  33. "REGISTERS:" return(REGISTERHEAD);
  34. "TOKENS:" return(TOKENHEAD);
  35. "TOKENEXPRESSIONS:" return(EXPRESSIONHEAD);
  36. "CODE:" return(CODEHEAD);
  37. "MOVES:" return(MOVEHEAD);
  38. "TESTS:" return(TESTHEAD);
  39. "STACKS:" return(STACKHEAD);
  40. "SIZEFACTOR" return(SIZEFAC);
  41. "TIMEFACTOR" return(TIMEFAC);
  42. "FORMAT" return(FORMAT);
  43. "cost" return(COST);
  44. "remove" return(REMOVE);
  45. "|" return(SEP);
  46. "samesign" return(SAMESIGN);
  47. "inreg" return(INREG);
  48. "sfit" return(SFIT);
  49. "ufit" return(UFIT);
  50. "defined" return(DEFINED);
  51. "rom" return(ROM);
  52. "loww" return(LOWW);
  53. "highw" return(HIGHW);
  54. "move" return(MOVE);
  55. "erase" return(ERASE);
  56. "allocate" return(ALLOCATE);
  57. "tostring" return(TOSTRING);
  58. "nocc" return(NOCC);
  59. "setcc" return(SETCC);
  60. "samecc" return(SAMECC);
  61. "test" return(TEST);
  62. "STACK" return(STACK);
  63. "nocoercions" return(NOCOERC);
  64. "&&" return(AND2);
  65. "||" return(OR2);
  66. "==" return(CMPEQ);
  67. "!=" return(CMPNE);
  68. "<=" return(CMPLE);
  69. "<" return(CMPLT);
  70. ">" return(CMPGT);
  71. ">=" return(CMPGE);
  72. ">>" return(RSHIFT);
  73. "<<" return(LSHIFT);
  74. "!" return(NOT);
  75. "~" return(COMP);
  76. "..." return(ELLIPS);
  77. EM_WSIZE { yylval.yy_intp = &wsize; return(CIDENT); }
  78. EM_PSIZE { yylval.yy_intp = &psize; return(CIDENT); }
  79. EM_BSIZE { yylval.yy_intp = &bsize; return(CIDENT); }
  80. REGISTER { yylval.yy_string = "REGISTER"; return(TYPENAME); }
  81. INT { yylval.yy_string = "INT"; return(TYPENAME); }
  82. STRING { yylval.yy_string = "STRING"; return(TYPENAME); }
  83. regvar return(REGVAR);
  84. loop return(LOOP);
  85. pointer return(POINTER);
  86. float return(FLOAT);
  87. return return(RETURN);
  88. [_A-Za-z][_A-Za-z0-9]+ {register ident_p ip;
  89. if(!lookident || (ip=ilookup(yytext,JUSTLOOKING))==0) {
  90. yylval.yy_string = scopy(yytext);return(IDENT);
  91. } else {
  92. yylval.yy_ident = ip;
  93. switch(ip->i_type) {
  94. default:assert(0);
  95. case IREG:return(RIDENT);
  96. case IPRP:return(PIDENT);
  97. case ITOK:return(TIDENT);
  98. case IEXP:return(EIDENT);
  99. }
  100. }
  101. }
  102. [a-z] {yylval.yy_char = yytext[0]; return(LCASELETTER);}
  103. [0-9]* {yylval.yy_int = atoi(yytext);return(NUMBER);}
  104. (\"|"%)") { char *p; int c,tipe; char stringbuf[BUFSIZ];
  105. p=stringbuf;
  106. for (;;) {
  107. c = input();
  108. switch(c) {
  109. default: *p++=c;break;
  110. case '\\':
  111. *p++=c; *p++=input(); break;
  112. case '\n':
  113. yyerror("Unterminated string");
  114. unput(c);
  115. /* fall through */
  116. case '"':
  117. tipe=STRING; goto endstr;
  118. case '%':
  119. c=input();
  120. if (c == '(') {
  121. tipe=LSTRING;goto endstr;
  122. } else {
  123. *p++ = '%'; unput(c); break;
  124. }
  125. }
  126. }
  127. endstr:
  128. *p++ = 0;
  129. yylval.yy_string = scopy(stringbuf);
  130. return(tipe);
  131. }
  132. ^\#(line)?[ \t]*[0-9]+[ \t]+\".*\".*$ {
  133. int ind,ind2;
  134. for (ind=0; yytext[ind] < '0' || yytext[ind]>'9'; ind++)
  135. ;
  136. lineno=atoi(&yytext[ind])-1;
  137. for(;yytext[ind]!='"';ind++)
  138. ;
  139. for(ind2=ind+1;yytext[ind2]!='"';ind2++)
  140. ;
  141. yytext[ind2]=0;
  142. if (!iname || strcmp(yytext+ind+1,iname)!=0)
  143. iname=scopy(yytext+ind+1);
  144. }
  145. [ \t]* ;
  146. \n { lineno++; }
  147. . return(yytext[0]);
  148. %%
  149. yyerror(s,a1,a2,a3,a4) string s; {
  150. fprintf(stderr,"\"%s\", line %d:",iname ? iname : "",lineno);
  151. fprintf(stderr,s,a1,a2,a3,a4);
  152. fprintf(stderr,"\n");
  153. nerrors++;
  154. }