-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbas.l
51 lines (37 loc) · 1.1 KB
/
bas.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
%option yylineno
%{
#include <bits/stdc++.h>
#include "bas.tab.h"
void yyerror(char *);
%}
printable [\x20-\x7E]
%%
[ \n\t\r]+ ;/* ignore whitespaces */
"/*"{printable}*"*/" ;/* Ignore Comments */
"const" {return CONST;}
"int" {return INT;}
"float" {return FLOAT;}
"char" {return CHAR;}
"bool" {return BOOL;}
"true" {return B_TRUE;}
"false" {return B_FALSE;}
"{" {return '{';}
"}" {return '}';}
"(" {return '(';}
")" {return ')';}
";" {return ';';}
"=" {return '=';}
"+" {return '+';}
"-" {return '-';}
"*" {return '*';}
"/" {return '/';}
[a-zA-Z_][a-zA-Z_0-9]* {yylval.val = strdup(yytext); return VAR;}
[+-]?[0-9]+ {yylval.val = strdup(yytext); return INTEGER;}
[+-]?[0-9]+['.'][0-9]* {yylval.val = strdup(yytext); return DECIMAL;}
\'.?\' {yylval.val = strdup(yytext); return CHARACTER;}
<<EOF>> {return ENDOFFILE;}
. yyerror("Unknown Token");
%%
int yywrap(void){
return 1;
}