%option noyywrap nounput noinput %{ #include "gen_parser.hpp" #include #include using bp = ::pslang::parser::bison::parser; #define YY_DECL bp::symbol_type yylex(::pslang::parser::context& ctx) #define YY_USER_ACTION ctx.location.columns(yyleng); %} %% %{ ctx.location.step(); %} [ ]+ { ctx.location.step(); } const { return bp::make_const(ctx.location); } let { return bp::make_let(ctx.location); } mut { return bp::make_mut(ctx.location); } if { return bp::make_if(ctx.location); } else { return bp::make_else(ctx.location); } while { return bp::make_while(ctx.location); } as { return bp::make_as(ctx.location); } true { return bp::make_true(ctx.location); } false { return bp::make_false(ctx.location); } bool { return bp::make_bool(ctx.location); } i8 { return bp::make_i8(ctx.location); } u8 { return bp::make_u8(ctx.location); } i16 { return bp::make_i16(ctx.location); } u16 { return bp::make_u16(ctx.location); } i32 { return bp::make_i32(ctx.location); } u32 { return bp::make_u32(ctx.location); } i64 { return bp::make_i64(ctx.location); } u64 { return bp::make_u64(ctx.location); } f32 { return bp::make_f32(ctx.location); } f64 { return bp::make_f64(ctx.location); } [a-z]+ { return bp::make_name(yytext, ctx.location); } "\n" { ctx.location.lines(1); return bp::make_newline(ctx.location); } "\t" { return bp::make_indent(ctx.location); } "=" { return bp::make_assignment(ctx.location); } ":" { return bp::make_colon(ctx.location); } "(" { return bp::make_lparen(ctx.location); } ")" { return bp::make_rparen(ctx.location); } "+" { return bp::make_plus(ctx.location); } "-" { return bp::make_minus(ctx.location); } "*" { return bp::make_asterisk(ctx.location); } "/" { return bp::make_slash(ctx.location); } "%" { return bp::make_percent(ctx.location); } "&" { return bp::make_ampersand(ctx.location); } "|" { return bp::make_vertical_bar(ctx.location); } "^" { return bp::make_circumflex(ctx.location); } "!" { return bp::make_exclamation(ctx.location); } "==" { return bp::make_equals(ctx.location); } "!=" { return bp::make_not_equals(ctx.location); } "<" { return bp::make_less(ctx.location); } ">" { return bp::make_greater(ctx.location); } "<=" { return bp::make_less_equals(ctx.location); } ">=" { return bp::make_greater_equals(ctx.location); } [0-9]+b { return bp::make_lit_i8(yytext, ctx.location); } [0-9]+ub { return bp::make_lit_u8(yytext, ctx.location); } [0-9]+s { return bp::make_lit_i16(yytext, ctx.location); } [0-9]+us { return bp::make_lit_u16(yytext, ctx.location); } [0-9]+ { return bp::make_lit_i32(yytext, ctx.location); } [0-9]+u { return bp::make_lit_u32(yytext, ctx.location); } [0-9]+l { return bp::make_lit_i64(yytext, ctx.location); } [0-9]+ul { return bp::make_lit_u64(yytext, ctx.location); } [0-9]+\.[0-9]+ { return bp::make_lit_f32(yytext, ctx.location); } [0-9]+\.[0-9]+l { return bp::make_lit_f64(yytext, ctx.location); } <> { return bp::make_end(ctx.location); } . { throw ::pslang::parser::parse_error("unexpected character \"" + std::string(yytext) + "\"", ctx.location); }