aoc-2022/day_9/lexer.l

57 lines
1.3 KiB
Text
Raw Permalink Normal View History

2023-01-15 11:00:18 +00:00
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.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]
SPACE " "
DOWN "D"
UP "U"
LEFT "L"
RIGHT "R"
/*general definitions*/
NUM [0-9]
%%
{NL} { return NEWLINE; }
{SPACE} { /* return SPACE; */ }
{DOWN} { return DOWN; }
{UP} { return UP; }
{LEFT} { return LEFT; }
{RIGHT} { return RIGHT; }
{NUM}+ {
unsigned long num = strtoul(yytext, NULL, 10);
yylval->num = num;
return NUM;
}
<<EOF>> {
return END_OF_FILE;
}
. {
printf("[error] Encountered unexpected token %s\n", yytext);
return 0;
}
%%