%{ #include extern int yylval; extern int symcount; extern int strcount; typedef struct { char mysymbol[20]; int value;} SYMBOL_TBL; char str_tbl[100][80]; SYMBOL_TBL sym_tbl[100]; #include "y.tab.h" int x; %} letter [A-Za-z] digit [0-9] ident {letter}({letter}|{digit})* op "+"|"-"|"*"|"/"|"("|")"|";"|"<"|">" ws [ \t\n]+ other . %% {ws} ; "if" { return IF;} "then" { return THEN;} "else" { return ELSE;} "while" { return WHILE;} "do" { return DO; } "print" { return PRINT;} "endif" { return ENDIF;} "endwhile" { return ENDWHILE;} "read" { return READ;} ">=" { return GE;} "<=" { return LE;} \".*\" { yylval = installs(yytext); return STR;} "newline" { return NEWLINE; } {ident} { yylval = install(yytext,0); return ID; } {op} return yytext[0]; {digit}+ { sscanf(yytext,"%d",&x); yylval = install(yytext,x); return NUM; } "==" return EQEQ; "=" return ASSIGN; . return yytext[0]; %% int install(char *ident, int val) { int i; i = 1; while ((i <= symcount) && strcmp(ident, sym_tbl[i].mysymbol)) i++; if (i <= symcount) return i; else { symcount++; strcpy(sym_tbl[symcount].mysymbol,ident); sym_tbl[symcount].value = val; return symcount; } } int installs(char *val) { int j,i; char x[80]; for (j=1;j