ͼ 4.15 LEX³ÌÐòÀý×Ó--ʶ±ðPL/0µ¥´ÊµÄLEX³ÌÐò
¡¡¡¡IDENT[a-zA-Z] [a-zA-Z0-9]*
¡¡¡¡NUMBER[0-9] [0-9]*
¡¡¡¡%(
¡¡¡¡#include ¡´stdio.h¡µ
¡¡¡¡#include "code.h"
¡¡¡¡#include "symbol.h"
¡¡¡¡#include "y.tab.h"
¡¡¡¡extern int level;
¡¡¡¡int cc=0;
¡¡¡¡%)
¡¡¡¡%%
¡¡¡¡"" { cc++;}
¡¡¡¡"£Üt" { tablize(); } /*adjustcc to tabª²position*/
¡¡¡¡"£Ün" { cc=0; lineª­-copy(); } /*copy a line of input file*/
¡¡¡¡"<" { cc++; return LT;}
¡¡¡¡">" { cc++; return GT;}
¡¡¡¡"=" { cc++; return EQ;}
¡¡¡¡"#" { cc++; return NE;}
¡¡¡¡"," { cc++; return colon; }
¡¡¡¡"." { cc++; return Period;}
¡¡¡¡"(" { cc++; return Lparen;}
¡¡¡¡")" { cc++; return Rparen;}
¡¡¡¡"<=" { cc++;cc++;return LE;}
¡¡¡¡">=" { cc++;cc++;return GE;}
¡¡¡¡"¡Ã=" { cc++; cc++;return ASGN;}
¡¡¡¡";" { cc++; return Semicolon;}
¡¡¡¡{NUMBER} {
¡¡¡¡¡¡¡¡¡¡¡¡¡¡intn;
¡¡¡¡¡¡¡¡¡¡¡¡¡¡cc += yyleng;
¡¡¡¡¡¡¡¡¡¡¡¡¡¡sscanf(yytext,"%d", &n);
¡¡¡¡¡¡¡¡¡¡¡¡¡¡yylval.number=n;
¡¡¡¡¡¡¡¡¡¡¡¡¡¡return NUMBER;
¡¡¡¡¡¡¡¡¡¡¡¡ }
¡¡¡¡{IDENT} {
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Symbol *s;
¡¡¡¡¡¡¡¡¡¡¡¡¡¡cc += yyleng;
¡¡¡¡¡¡¡¡¡¡¡¡¡¡if((s=lookup(yytext))==0) /*new identifier*/
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡s=install(yytext,VARIABLE,level,0); /* install symbol*/
¡¡¡¡¡¡¡¡¡¡¡¡¡¡if (s¡útype==C)
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡yylval.number=s-¡µadr;
¡¡¡¡¡¡¡¡¡¡¡¡¡¡else /*it's a VARIABLE or PROC*/
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡yylval.sym=s;
¡¡¡¡¡¡¡¡¡¡¡¡¡¡return s-¡µtype;
¡¡¡¡¡¡¡¡¡¡¡¡}
¡¡¡¡%%
¡¡¡¡yywrap( ) {ª²ª²ª²
¡¡¡¡};