-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.l
34 lines (26 loc) · 932 Bytes
/
lexer.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
%option noyywrap
%{
#include "parser.tab.hpp"
#define YY_DECL yy::parser::symbol_type yylex()
%}
%%
"sin" { return yy::parser::make_SIN(); }
"cos" { return yy::parser::make_COS(); }
"exp" { return yy::parser::make_EXP(); }
"ln" { return yy::parser::make_LN(); }
"(" { return yy::parser::make_LPAREN(); }
")" { return yy::parser::make_RPAREN(); }
"+" { return yy::parser::make_ADD(); }
"-" { return yy::parser::make_SUB(); }
"*" { return yy::parser::make_MUL(); }
"/" { return yy::parser::make_DIV(); }
"^" { return yy::parser::make_POW(); }
";" { return yy::parser::make_SEMICOLON(); }
"=" { return yy::parser::make_EQUALS(); }
"," { return yy::parser::make_COMMA(); }
[a-z] { return yy::parser::make_VAR(yytext); }
([0-9]+)|([0-9]+\.[0-9]+) { return yy::parser::make_NUM(std::stod(yytext)); }
[ \t] { }
. { std::cout << "Ignoring unknown character: " << yytext << std::endl; }
<<EOF>> { return yy::parser::make_END(); }
%%