-
Notifications
You must be signed in to change notification settings - Fork 0
/
minipy-lab.l
49 lines (40 loc) · 1022 Bytes
/
minipy-lab.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
%{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "jiegou.h"
#define YYSTYPE val
extern val yylval;
#include "minipy-lab.tab.h"
/* any C declaration */
%}
letter [a-zA-Z]
digit [0-9]
number {digit}+
id {letter}({letter}|{digit})*
real {number}"."{number}?|{number}?"."{number}
%%
[ \t]+ {/*do nothing , just skip */}
{number} {
yylval.type=INt;
yylval.i=atoi(yytext);
return INT;
}
{real} {
yylval.type=REAl;
yylval.r=atof(yytext);
return REAL;
}
{id} {
yylval.type=Id;
strcpy(yylval.id,yytext);
strcpy(yylval.func,yytext);
return ID;
}
\"(\\.|[^\\"])*\" {
yylval.type=STRING;
strcpy(yylval.str,yytext);
return(STRING_LITERAL);
}
.|\n { return yytext[0];}
%%