aoc-2022/day_2-2/lexer.l

46 lines
938 B
Text
Raw Normal View History

2022-12-26 12:36:26 +00:00
%{ /* -*- C -*- */
#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 [ \t]
2022-12-26 13:12:48 +00:00
ROCK [A]
PAPER [B]
SCISSOR [C]
LOSS [X]
DRAW [Y]
WIN [Z]
2022-12-26 12:36:26 +00:00
%%
{NL} { return NEWLINE; }
{SPACE}+ { /* don't care */}
{ROCK} { return ROCK; }
{PAPER} { return PAPER; }
{SCISSOR} { return SCISSOR; }
2022-12-26 13:12:48 +00:00
{LOSS} { return LOSS; }
{DRAW} { return DRAW; }
{WIN} { return WIN; }
2022-12-26 12:36:26 +00:00
<<EOF>> { return END_OF_FILE; }
. {
printf("[error] Encountered unexpected token %s\n", yytext);
return 0;
}
%%