aoc-2022/day_6/lexer.l

42 lines
933 B
Text
Raw Permalink Normal View History

2022-12-28 10:46:31 +00:00
%{
#include <stdio.h>
#include <stdlib.h>
#include "parser.h"
%}
%option warn nodefault
/* makes the scanner terminate after reaching <<EOF>> instead of assuming a new input was provided */
%option noyywrap
/* disable some unused functionality, add scanner tracking */
%option nounput noinput batch debug
/* gimme a reentrant parser (overkill but more pure) */
%option reentrant
%option bison-bridge
NL [\n]
CHAR [a-z]
%%
{NL} {
return NEWLINE;
}
{CHAR} {
yylval->cval = yytext[0];
return CHAR;
}
<<EOF>> {
return END_OF_FILE;
}
. {
printf("[error] Encountered unexpected token %s\n", yytext);
return 0;
}
%%