-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexer.l
64 lines (58 loc) · 1.92 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
%{
#include<stdlib.h>
#include<stdio.h>
#include <stdarg.h>
#include <string.h>
#include "parser.tab.h"
void yyerror(char *s);
%}
%%
int return INT;
bool return BOOLEAN;
char return CHARACTER;
float return FLOAT;
string return STRING;
const return CONSTANT;
void return VOID;
if return IF;
else return ELSE;
switch return SWITCH;
case return CASE;
default return DEFAULT;
for return FOR;
do return DO;
while return WHILE;
break return BREAK;
continue return CONTINUE;
return return RETURN;
"==" return EQUAL;
"!=" return NOT_EQUAL;
">" return GREATER_THAN;
"<" return LESS_THAN;
">=" return GREATER_EQUAL;
"<=" return LESS_EQUAL;
"&&" return AND;
"||" return OR;
"!" return NOT;
"=" return ASSIGNMENT;
";" return SEMICOLON;
"," return COMMA;
":" return COLON;
[-+*/{}~^&|(),:=%] return yytext[0];
true|false yylval=!strcmp(yytext,"true"); return BOOLEAN_TYPE;
[0-9]+ yylval=atoi(yytext); return INT_TYPE;
[0-9]*\.[0-9]+ yylval=strdup(yytext);return FLOAT_TYPE;
['][a-zA-Z]['] yylval=yytext[1]; return CHARACTER_TYPE;
\"[^"]*\" return STRING_TYPE;
[a-zA-Z\_][0-9a-zA-Z\_]* yylval=strdup(yytext); return IDENTIFIER;
\/\/[^\n].* ;
\/\*[^*]*\*\/ ;
[ \t\n]+ ;
%%
/*
* Called whenever the scanner reaches the end of file.
* If yywrap() returns 1, the scanner continues with normal wrapup on the end of input.
*/
int yywrap(void) {
return 1;
}