-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.l
52 lines (49 loc) · 1.2 KB
/
code.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
%option noyywrap
%{
#include "y.tab.h"
#include <stdio.h>
#include <stdlib.h>
%}
DIGIT [0-9]
ALPHABET [a-zA-Z_]
EQ [=]
%%
"if" { return IF; }
"else" { return ELSE; }
"while" { return WHILE; }
"switch" { return SWITCH; }
"break" { return BREAK; }
"case" { return CASE; }
"default" { return DEFAULT; }
"int" { strcpy(yylval.lexeme, yytext); return INT; }
"float" { strcpy(yylval.lexeme, yytext); return FLOAT; }
"char" { strcpy(yylval.lexeme, yytext); return CHAR; }
{ALPHABET}+({DIGIT}|{ALPHABET})* { strcpy(yylval.lexeme, yytext); return VAR; }
"\+\+" { return PREPOSTADD; }
"\-\-" { return PREPOSTSUB; }
"\+" { return ADD; }
"\-" { return SUB; }
"*" { return MUL; }
"/" { return DIV; }
{EQ} { return EQ; }
"<" { return LT; }
"<=" { return LTE;}
">" { return GT; }
">=" { return GTE; }
"&&" { return AND; }
"||" { return OR; }
"!" { return NOT; }
{DIGIT}+("."{DIGIT}+)? { strcpy(yylval.lexeme, yytext); return NUMBER; }
[ \t\n] ; /* handle whitespaces and new lines */
"\(" { return LPAREN; }
"\)" { return RPAREN; }
"[" { return LBRAK; }
"]" { return RBRAK; }
"{" { return LCURL; }
"}" { return RCURL; }
"," { return COMMA; }
":" { return COLON; }
";" { return SEMICOLON; }
<<EOF>> { return EOF; }
. { return yytext[0]; }
%%`