forked from harshitag456/Compilers-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflex.l
More file actions
56 lines (51 loc) · 1.45 KB
/
flex.l
File metadata and controls
56 lines (51 loc) · 1.45 KB
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
%{
#include <stdlib.h>
#include <string.h>
#include <bits/stdc++.h>
#include "bison.tab.h"
using namespace std;
extern int lineno;
%}
%option noyywrap
%%
"[" return LB;
"]" return RB;
"&&" return AND ;
"||" return OR;
"!" return NOT;
int[' '\t]+ return INT;
float[' '\t]+ return FLOAT ;
\( return LP;
\) return RP;
"<=" return LE;
">=" return GE;
"==" return EE;
"<" return LT;
">" return GT;
"=" return EQ;
"*" return STAR;
"+" return PLUS;
"/" return DIVIDE;
"-" return MINUS;
";" return SEMI;
"," return COMMA;
"while" return WHILE;
"for" return FOR;
"{" return LC;
"}" return RC;
"if" return IF;
"else" return ELSE;
"return" return RETURN;
"switch" return SWITCH;
"break" return BREAK;
"case" return CASE;
":" return COLON;
"default" return DEFAULT;
[a-zA-Z][a-zA-Z0-9_]* strcpy(yylval.idName, yytext); return ID ;
" "
"-"[0-9]+ yylval.val = atoi(yytext); return NUM;
[0-9]+ yylval.val = atoi(yytext); return NUM;
[0-9]+"."[0-9]+ yylval.data = atof(yytext); return DECIMAL;
"-"[0-9]+"."[0-9]+ yylval.data = atof(yytext); return DECIMAL;
\n lineno++;
%%