blog-static/code/compiler/13/scanner.l

47 lines
1.8 KiB
Plaintext

%option noyywrap
%option reentrant
%option header-file="scanner.hpp"
%{
#include <iostream>
#include "ast.hpp"
#include "definition.hpp"
#include "parse_driver.hpp"
#include "parser.hpp"
#define YY_USER_ACTION drv.write(yytext, yyleng); drv.location.step(); drv.location.columns(yyleng);
%}
%%
\n { drv.location.lines(); drv.mark_line(); }
[ ]+ {}
\\ { 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); }
% { return yy::parser::make_MODULO(drv.location); }
== { return yy::parser::make_EQUALS(drv.location); }
\<= { return yy::parser::make_LESS_EQUALS(drv.location); }
` { return yy::parser::make_BACKTICK(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); }
%%