-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsilc.l
65 lines (50 loc) · 1.16 KB
/
silc.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
56
57
58
59
60
61
62
%{
#include <stdlib.h>
#include "y.tab.h"
#include "operators.h"
#include "types.h"
int lineno=1;
%}
%%
/* whitespace */
[ \t] ;
[\n] {lineno++;}
">=" { yylval.i=CH_GE; return RELOP; }
"<=" { yylval.i=CH_LE; return RELOP; }
"==" { yylval.i=CH_EQ; return RELOP; }
"!=" { yylval.i=CH_NE; return RELOP; }
">" { yylval.i=CH_GT; return RELOP; }
"<" { yylval.i=CH_LT; return RELOP; }
"&&" { yylval.i=CH_LOGAND; return LOGOP; }
"||" { yylval.i=CH_LOGOR; return LOGOP; }
"while" return WHILE;
"do" return DO;
"endwhile" return ENDWHILE;
"if" return IF;
"else" return ELSE;
"endif" return ENDIF;
"print" return WRITE;
"read" return READ;
"write" return WRITE;
"decl" return DECL;
"true" return TRUE;
"false" return FALSE;
"enddecl" return ENDDECL;
"integer" return INTEGER;
"boolean" return BOOLEAN;
"end" return END;
"return" return RETURN;
"main" return MAIN;
/* integers constant*/
[0-9]+ { yylval.nptr = node_const(TYPE_INT,atoi(yytext)); return CONSTANT; }
/* variables */
[a-zA-Z][A-Za-z0-9]* {yylval.name=strdup(yytext);return IDENT; }
/* operators */
[-()=+*/;&,\[\]{}] { return *yytext;}
/* others */
. yyerror("Invalid character");
%%
int yywrap(void)
{
return 1;
}