aoc-2022/day_1/lexer.l

44 lines
903 B
Text
Raw Permalink Normal View History

2022-12-27 21:31:14 +00:00
%{
2022-12-25 20:15:50 +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]
NUM [0-9]
%%
{NL} {
return NEWLINE;
}
{NUM}+ {
2022-12-25 22:09:12 +00:00
unsigned long num = strtoul(yytext, NULL, 10);
// printf("number: %d\n", num);
2022-12-25 20:15:50 +00:00
yylval->num = num;
return NUMBER;
}
<<EOF>> {
return END_OF_FILE;
}
. {
printf("[error] Encountered unexpected token %s\n", yytext);
return 0;
}
%%