-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlisp.l
51 lines (39 loc) · 825 Bytes
/
mlisp.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
%{
#include <memory>
#include "node.h"
#include "mlisp.tab.hpp"
%}
%option noyywrap
%%
"+" return PLUS;
"-" return MINUS;
"*" return MUL;
"/" return DIV;
"mod" return MOD;
">" return GREATER;
"<" return LESS;
"=" return EQUAL;
"and" return AND;
"or" return OR;
"not" return NOT;
"print-num" return PRINT_NUMBER;
"print-bool" return PRINT_BOOLEAN;
"define" return DEFINE;
"if" return IF;
"fun" return FUN;
"0"|([1-9][0-9]*)|(-[1-9][0-9]*) {
yylval = std::make_shared<node>(node_type::integer, std::stoi(yytext));
return NUMBER;
}
"#"[tf] {
yylval = std::make_shared<node>(node_type::boolean, yytext[1] == 't');
return BOOLEAN;
}
[a-z]([a-z0-9\-])* {
yylval = std::make_shared<node>(node_type::id, std::string{yytext});
return ID;
}
[()] return yytext[0];
[ \t\n\r] ;
. return yytext[0];
%%