%option noyywrap %option reentrant %{ #include #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); } [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); } <> { 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); }