%{ #include "c.h" #include "y.tab.h" extern int lineno; %} digit [0-9] num {digit}+\.?|{digit}*\.{digit}+ letter [a-zA-Z] id {letter}({letter}|{digit})* %% [ \t] { printf("%s", yytext); } /* skip blanks and tabs */ {num} { sscanf(yytext, "%lf", &yylval.val); yylval.sym = install("", NUMBER, yylval.val); printf("%s", yytext); return NUMBER; } {id} { Symbol *s; if ((s=lookup(yytext)) == 0) s = install(yytext, UNDEF, 0.0); yylval.sym = s; printf("%s", yytext); return s->type == UNDEF ? ID : s->type; } "=" { printf("%s", yytext); return ASSIGN; } "!=" { printf("%s", yytext); return NE; } "<" { printf("%s", yytext); return follow('=', LE, LT); } ">" { printf("%s", yytext); return follow('=', GE, GT); } "==" { printf("%s", yytext); return EQ; } \n { printf("%s", yytext); lineno++; } . { printf("%s", yytext); return yytext[0]; } /* everything else */ %% follow(expect, ifyes, ifno) /* look ahead for >=, etc. */ { int c = getchar(); if (c == expect) { printf("%c", c); return ifyes; } ungetc(c, stdin); return ifno; }