A Hugo incarnation of the blog. https://danilafe.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

57 lines
2.0 KiB

%option noyywrap
%option reentrant
%{
#include <iostream>
#include "ast.hpp"
#include "definition.hpp"
#include "parse_driver.hpp"
#include "parser.hpp"
#define YY_EXTRA_TYPE parse_driver*
#define YY_USER_ACTION drv.location.step(); drv.location.columns(yyleng);
#define YY_INPUT(buf,result,max_size) \
{ \
int c = yyextra->get(); \
result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
}
%}
%%
\n { drv.location.lines(); }
[ ]+ {}
\\ { 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); }
[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); }
%%
void scanner_init(parse_driver* d, yyscan_t* scanner) {
yylex_init_extra(d, scanner);
}
void scanner_destroy(yyscan_t* scanner) {
yylex_destroy(*scanner);
}