-
Notifications
You must be signed in to change notification settings - Fork 0
/
lisp.l
55 lines (49 loc) · 1.02 KB
/
lisp.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
52
53
54
55
%option noyywrap
%{
#include "y.tab.h"
#include <stdio.h>
// 參考專案 : https://github.com/Zane2453/Mini-LISP-interpreter_Lex-Yacc
// 還有 https://github.com/q23175401/complier-final-miniLisp
// 大家好像都會參考一下這兩個,粗事了
%}
digit [0-9]
letter [a-z]
number 0|[1-9]{digit}*|-[1-9]{digit}*
id {letter}({letter}|{digit}|-)*
%%
"print-num" {return PRINTNUM;}
"print-bool" {return PRINTBOOL;}
"+" {return '+';}
"-" {return '-';}
"*" {return '*';}
"/" {return '/';}
"mod" {return '%';}
">" {return '>';}
"<" {return '<';}
"=" {return '=';}
"and" {return '&';}
"or" {return '|';}
"not" {return '!';}
"define" {return 'd';}
"lambda" {return 'l';}
"fun" {return 'l';} // 講義寫fun,測資給lambda,所以我決定兩個都收
"if" {return 'i';}
{number} {
yylval.intval = atoi(yytext);
return NUMBER;
}
"#t" {
yylval.boolval=1;
return BOOL;
}
"#f" {
yylval.boolval=0;
return BOOL;
}
{id} {
yylval.strval = strdup(yytext);
return ID;
}
"("|")" {return yytext[0];}
.|\n {;}
%%