forked from ahmedihabb2/MangaCC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.l
73 lines (64 loc) · 1.94 KB
/
scanner.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
65
66
67
68
69
70
71
72
73
%{
#include "parser.tab.h"
void yyerror (char *s);
int line_num = 1;
%}
%%
"if" {return IF;}
"endif" {return ENDIF;}
"else" {return ELSE;}
"else if" {return ELSEIF;}
"while" {return WHILE;}
"for" {return FOR;}
"break" {return BREAK;}
"continue" {return CONTINUE;}
"return" {return RETURN;}
"int" {return INTTYPE;}
"float" {return FLOATTYPE;}
"bool" {return BOOLTYPE;}
"string" {return STRINGTYPE;}
"void" {return VOID;}
"print" {return PRINT;}
"const" {return CONST;}
"repeat" {return REPEAT;}
"until" {return UNTIL;}
"switch" {return SWITCH;}
"case" {return CASE;}
"default" {return DEFAULT;}
"enum" {return ENUM;}
"exit" {return EXIT;}
"+" {return PLUS;}
"-" {return MINUS;}
"*" {return TIMES;}
"/" {return DIV;}
"%" {return MOD;}
"=" {return ASSIGN;}
"(" {return LPAREN;}
")" {return RPAREN;}
"{" {return LBRACE;}
"}" {return RBRACE;}
";" {return SEMI;}
":" {return COLON;}
"<" {return LT;}
">" {return GT;}
"," {return COMMA;}
"==" {return EQ;}
"!=" {return NE;}
"<=" {return LE;}
">=" {return GE;}
"and" {return AND;}
"or" {return OR;}
"not" {return NOT;}
"xor" {return XOR;}
"true"|"false" {yylval.boolean = yytext[0]=='t'; return BOOL;}
[ \t]+ {;}
\/\/.* {;}
\n {line_num++;}
[-]?[0-9]+ {yylval.integer = atoi(yytext); return INT;}
[-]?[0-9]+\.[0-9]+ {yylval.floatval = atof(yytext); return FLOAT;}
[a-zA-Z_][a-zA-Z0-9_]* {yylval.id = strdup(yytext); return ID;}
\".*\" {yylval.string = strdup(yytext); return STRING;}
\'.*\' {yylval.string = strdup(yytext); return STRING;}
. {yyerror("Unexpected Token");}
%%
int yywrap (void) {return 1;}