-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.l
43 lines (41 loc) · 1.1 KB
/
lexer.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
%{
#define YYSTYPE char*
#include <unistd.h>
#include "y.tab.h"
#include <stdio.h>
extern void yyerror(const char *); // declare the error handling function
%}
/* Regular definitions */
digit [0-9]
letter [a-zA-Z]
id {letter}({letter}|{digit})*
digits {digit}+
opFraction (\.{digits})?
opExponent ([Ee][+-]?{digits})?
number {digits}{opFraction}{opExponent}
%option yylineno
%%
\/\/(.*) ; // ignore comments
[\t\n] ; // ignore whitespaces
"(" {return *yytext;}
")" {return *yytext;}
"." {return *yytext;}
"," {return *yytext;}
"*" {return *yytext;}
"+" {return *yytext;}
";" {return *yytext;}
"-" {return *yytext;}
"/" {return *yytext;}
"=" {return *yytext;}
">" {return *yytext;}
"<" {return *yytext;}
{number} {
yylval = strdup(yytext); //stores the value of the number to be used later for symbol table insertion
return T_NUM;
}
{id} {
yylval = strdup(yytext); //stores the identifier to be used later for symbol table insertion
return T_ID;
}
. {} // anything else => ignore
%%