68 lines
1.7 KiB
Text
68 lines
1.7 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 [ ]
|
|
NUM [0-9]
|
|
CRATE_DELIM_OPEN "["
|
|
CRATE_DELIM_CLOSE "]"
|
|
CRATE_ID [A-Z]
|
|
|
|
|
|
%%
|
|
|
|
{NL} {
|
|
return NEWLINE;
|
|
}
|
|
{SPACE} {
|
|
return SPACE;
|
|
}
|
|
{NUM}+ {
|
|
unsigned long num = strtoul(yytext, NULL, 10);
|
|
yylval->num = num;
|
|
return NUMBER;
|
|
}
|
|
{CRATE_DELIM_OPEN} {
|
|
return CRATE_DELIM_OPEN;
|
|
}
|
|
{CRATE_DELIM_CLOSE} {
|
|
return CRATE_DELIM_CLOSE;
|
|
}
|
|
{CRATE_ID} {
|
|
yylval->cval = yytext[0];
|
|
return CRATE_ID;
|
|
}
|
|
"move " {
|
|
return MOVE_OP;
|
|
}
|
|
" from " {
|
|
return ORIGIN;
|
|
}
|
|
" to " {
|
|
return DEST;
|
|
}
|
|
<<EOF>> {
|
|
return END_OF_FILE;
|
|
}
|
|
. {
|
|
printf("[error] Encountered unexpected token %s\n", yytext);
|
|
return 0;
|
|
}
|
|
|
|
%%
|