2020-09-08 18:38:05 -07:00
|
|
|
%option noyywrap
|
2020-09-09 13:00:06 -07:00
|
|
|
%option reentrant
|
2020-09-11 02:16:29 -07:00
|
|
|
%option header-file="scanner.hpp"
|
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-15 18:51:28 -07:00
|
|
|
#define YY_USER_ACTION \
|
|
|
|
drv.get_file_manager().write(yytext, yyleng); \
|
|
|
|
LOC.step(); LOC.columns(yyleng);
|
|
|
|
#define LOC drv.get_current_location()
|
2020-09-08 18:38:05 -07:00
|
|
|
%}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2020-09-15 18:51:28 -07:00
|
|
|
\n { drv.get_current_location().lines(); drv.get_file_manager().mark_line(); }
|
2020-09-09 12:21:50 -07:00
|
|
|
[ ]+ {}
|
2020-09-15 18:51:28 -07:00
|
|
|
\\ { return yy::parser::make_BACKSLASH(LOC); }
|
|
|
|
\+ { return yy::parser::make_PLUS(LOC); }
|
|
|
|
\* { return yy::parser::make_TIMES(LOC); }
|
|
|
|
- { return yy::parser::make_MINUS(LOC); }
|
|
|
|
\/ { return yy::parser::make_DIVIDE(LOC); }
|
|
|
|
% { return yy::parser::make_MODULO(LOC); }
|
|
|
|
== { return yy::parser::make_EQUALS(LOC); }
|
|
|
|
\<= { return yy::parser::make_LESS_EQUALS(LOC); }
|
|
|
|
` { return yy::parser::make_BACKTICK(LOC); }
|
|
|
|
[0-9]+ { return yy::parser::make_INT(atoi(yytext), LOC); }
|
|
|
|
defn { return yy::parser::make_DEFN(LOC); }
|
|
|
|
data { return yy::parser::make_DATA(LOC); }
|
|
|
|
case { return yy::parser::make_CASE(LOC); }
|
|
|
|
of { return yy::parser::make_OF(LOC); }
|
|
|
|
let { return yy::parser::make_LET(LOC); }
|
|
|
|
in { return yy::parser::make_IN(LOC); }
|
|
|
|
\{ { return yy::parser::make_OCURLY(LOC); }
|
|
|
|
\} { return yy::parser::make_CCURLY(LOC); }
|
|
|
|
\( { return yy::parser::make_OPAREN(LOC); }
|
|
|
|
\) { return yy::parser::make_CPAREN(LOC); }
|
|
|
|
, { return yy::parser::make_COMMA(LOC); }
|
|
|
|
-> { return yy::parser::make_ARROW(LOC); }
|
|
|
|
= { return yy::parser::make_EQUAL(LOC); }
|
|
|
|
[a-z][a-zA-Z]* { return yy::parser::make_LID(std::string(yytext), LOC); }
|
|
|
|
[A-Z][a-zA-Z]* { return yy::parser::make_UID(std::string(yytext), LOC); }
|
|
|
|
<<EOF>> { return yy::parser::make_YYEOF(LOC); }
|
2020-09-08 18:38:05 -07:00
|
|
|
|
|
|
|
%%
|