-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple.lex
executable file
·53 lines (50 loc) · 915 Bytes
/
simple.lex
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
%{
#include <stdio.h>
#include "type.h"
#include <stdlib.h>
#include<string.h>
#include "y.tab.h"
%}
alpha [a-zA-Z_]
digit [0-9]
%%
[ \t] ;
CALL return CALL;
IF return IF;
ODD return ODD;
THEN return THEN;
WHILE return WHILE;
DO return DO;
CONST return CONST;
VAR return VAR;
PROCEDURE return PROCEDURE;
BEGIN return Begin;
END return END;
":=" return Assign;
"#" return yytext[0];
">=" return GE;
"<=" return LE;
">" return yytext[0];
"<" return yytext[0];
"=" return yytext[0];
"." return yytext[0];
";" return yytext[0];
"," return yytext[0];
"+" return yytext[0];
"-" return yytext[0];
"/" return yytext[0];
"*" return yytext[0];
{digit}+ {
yylval.num = atoi(yytext);
return NUMBER;
}
{alpha}({alpha}|{digit})* {
char *ptr_string;
ptr_string = (char *)calloc(strlen(yytext)+1, sizeof(char));
strcpy(ptr_string, yytext);
yylval.id = ptr_string;
return ID;
}
"\n" ;
. ;
%%