aoc-2022/day_10/lexer.l
2023-02-19 20:40:57 +01:00

51 lines
1.1 KiB
Text

%{
#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]
SPACE " "
NOP "noop"
ADD "addx"
/*general definitions*/
NUM [0-9\-]
%%
{NL} { return NEWLINE; }
{SPACE} { /* return SPACE; */ }
{NOP} { return NOP; }
{ADD} { return ADDX; }
{NUM}+ {
int num = atoi(yytext);
yylval->num = num;
return NUM;
}
<<EOF>> {
return END_OF_FILE;
}
. {
printf("[error] Encountered unexpected token %s\n", yytext);
return 0;
}
%%