|
CS456 - Systems Programming
Spring 2025
|
Displaying ./code/lexyacc/example7.l
/*
Compile with :
> lex example7.l
> yacc -d example7.y
> gcc lex.yy.c y.tab.c -o example7
*/
%{
#include <stdio.h>
#include <string.h>
#include "y.tab.h"
%}
%%
[0-9]+ yylval.number=atoi(yytext); return NUMBER;
heater return TOKHEATER;
heat return TOKHEAT;
on|off yylval.number=!strcmp(yytext,"on"); return STATE;
target return TOKTARGET;
temperature return TOKTEMPERATURE;
[a-z0-9]+ yylval.string=strdup(yytext);return WORD;
\n /* ignore end of line */;
[ \t]+ /* ignore whitespace */;
%%
|