-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproject.l
38 lines (37 loc) · 1.09 KB
/
project.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 <stdio.h>
#include <string.h>
#include "y.tab.h"
int linenum;
%}
%%
"int" return INT;
"if" return IF;
"else" return ELSE;
"return" return RETURN;
[0-9]+ {yylval.number = atoi(yytext); return INTEGER;}
[_a-zA-Z][_a-zA-Z0-9]* {yylval.string = strdup(yytext); return IDENTIFIER;}
"<" return LESSTHAN;
">" return GREATERTHAN;
"<=" return LESSEQUAL;
">=" return GREATEQUAL;
"." return DOT;
"," return COMMA;
"==" return EQUAL;
"!=" return NOTEQUAL;
"-" return MINUSOP;
"+" return PLUSOP;
"(" return OPENPAR;
")" return CLOSEPAR;
"{" return OPENCURL;
"}" return CLOSECURL;
"/" {;} // ignore DIVIDEOP;
"*" return MULTOP;
"=" return ASSIGNOP;
";" return SEMICOLON;
"\n" linenum++;
"#".*\n {;} /*ignore macros*/
[ \t]+ {;} /*ignore whitespaces*/
"/*".*"*/"|"//".*\n {;} /*ignore comments*/
. /*unexpected character*/
%%