-
Notifications
You must be signed in to change notification settings - Fork 0
/
f.l
38 lines (36 loc) · 1.34 KB
/
f.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
%{
#include "y.tab.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
%}
letter [a-z]
digit [0-9]
%%
0|[1-9]{digit}*|-[1-9]{digit}* {yylval.num=atoi(yytext);return NUMBER;}
(\#t) {yylval.num=1; return BOOL;}
(\#f) {yylval.num=0; return BOOL;}
"define" {return DEFINE;}
"lambda" {return LAMBDA;}
"if" {return IF;}
"print-num" {return PRINTNUM;}
"print-bool" {return PRINTBOOL;}
"mod" {return yytext[0];}
"and" {return yytext[0];}
"or" {return yytext[0];}
"not" {return yytext[0];}
{letter}({letter}|{digit}|\-)* {
char *tem=(char*)malloc(strlen(yytext));
for(int i=0;i<strlen(yytext);i++){
tem[i]=yytext[i];
}
yylval.id=tem;
return ID;
}
[\+\-\*\/\(\)\>\<\=] {return yytext[0];}
[\t\n\r ] {;}
. {printf("Unexpected Character! %s\n",yytext); exit(1);}
%%
int yywrap(void){
return 1;
}