2020-09-08 18:38:05 -07:00
|
|
|
%option noyywrap
|
2020-09-09 13:00:06 -07:00
|
|
|
%option reentrant
|
2020-09-08 18:38:05 -07:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include <iostream>
|
|
|
|
#include "ast.hpp"
|
|
|
|
#include "definition.hpp"
|
2020-09-09 13:00:06 -07:00
|
|
|
#include "parse_driver.hpp"
|
2020-09-08 18:38:05 -07:00
|
|
|
#include "parser.hpp"
|
|
|
|
|
2020-09-09 13:00:06 -07:00
|
|
|
#define YY_EXTRA_TYPE parse_driver*
|
2020-09-09 13:57:01 -07:00
|
|
|
#define YY_USER_ACTION drv.location.step(); drv.location.columns(yyleng);
|
2020-09-09 13:00:06 -07:00
|
|
|
#define YY_INPUT(buf,result,max_size) \
|
|
|
|
{ \
|
|
|
|
int c = yyextra->get(); \
|
|
|
|
result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
|
|
|
|
}
|
2020-09-08 18:38:05 -07:00
|
|
|
%}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2020-09-09 13:57:01 -07:00
|
|
|
\n { drv.location.lines(); }
|
2020-09-09 12:21:50 -07:00
|
|
|
[ ]+ {}
|
2020-09-09 13:57:01 -07:00
|
|
|
\\ { return yy::parser::make_BACKSLASH(drv.location); }
|
|
|
|
\+ { return yy::parser::make_PLUS(drv.location); }
|
|
|
|
\* { return yy::parser::make_TIMES(drv.location); }
|
|
|
|
- { return yy::parser::make_MINUS(drv.location); }
|
|
|
|
\/ { return yy::parser::make_DIVIDE(drv.location); }
|
|
|
|
[0-9]+ { return yy::parser::make_INT(atoi(yytext), drv.location); }
|
|
|
|
defn { return yy::parser::make_DEFN(drv.location); }
|
|
|
|
data { return yy::parser::make_DATA(drv.location); }
|
|
|
|
case { return yy::parser::make_CASE(drv.location); }
|
|
|
|
of { return yy::parser::make_OF(drv.location); }
|
|
|
|
let { return yy::parser::make_LET(drv.location); }
|
|
|
|
in { return yy::parser::make_IN(drv.location); }
|
|
|
|
\{ { return yy::parser::make_OCURLY(drv.location); }
|
|
|
|
\} { return yy::parser::make_CCURLY(drv.location); }
|
|
|
|
\( { return yy::parser::make_OPAREN(drv.location); }
|
|
|
|
\) { return yy::parser::make_CPAREN(drv.location); }
|
|
|
|
, { return yy::parser::make_COMMA(drv.location); }
|
|
|
|
-> { return yy::parser::make_ARROW(drv.location); }
|
|
|
|
= { return yy::parser::make_EQUAL(drv.location); }
|
|
|
|
[a-z][a-zA-Z]* { return yy::parser::make_LID(std::string(yytext), drv.location); }
|
|
|
|
[A-Z][a-zA-Z]* { return yy::parser::make_UID(std::string(yytext), drv.location); }
|
|
|
|
<<EOF>> { return yy::parser::make_YYEOF(drv.location); }
|
2020-09-08 18:38:05 -07:00
|
|
|
|
|
|
|
%%
|
2020-09-09 13:00:06 -07:00
|
|
|
|
|
|
|
void scanner_init(parse_driver* d, yyscan_t* scanner) {
|
|
|
|
yylex_init_extra(d, scanner);
|
|
|
|
}
|
|
|
|
void scanner_destroy(yyscan_t* scanner) {
|
|
|
|
yylex_destroy(*scanner);
|
|
|
|
}
|