-
Notifications
You must be signed in to change notification settings - Fork 2
/
lex.flex
73 lines (63 loc) · 1.6 KB
/
lex.flex
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 "parse.tab.h"
#include <iostream>
#include <cstdio>
using namespace std;
#define YY_DECL extern "C" int yylex()
void comment(void);
%}
%%
Show { return SHOW; }
if { return IF; }
Loop { return LOOP; }
to { return TO; }
$[a-z] {
yylval.chval = (int)yytext[1]-'a'+1;
return ID;
}
[0-9]+ {
yylval.dval = atoi(yytext);
return NUM;
}
[0-1]+b {
char *end;
yylval.dval = strtol(yytext,&end,2);
return NUM;
}
[0-9a-fA-F]+h {
char *endx;
yylval.dval = strtol(yytext,&endx,16);
return NUM;
}
"+" { return '+'; }
"-" { return '-'; }
"%" { return '%'; }
"*" { return '*'; }
"/" { return '/'; }
"==" { return EQUAL; }
"=" { return ASSIGN; }
":" { return ':'; }
"\n" { return END; }
"(" { return '('; }
")" { return ')'; }
";" { return ';'; }
"#" { comment(); }
"{" { return '{'; }
"}" { return '}'; }
\"[a-zA-z_0-9]+\" {
yylval.strval = yytext;
return STRING;
}
[ \t ' ' ]+ ;
.
%%
int yywrap ( void ) { }
void comment(void){
char c, c1;
loop:
while ((c = yyinput()) != '\\' && c != 0);
if ((c1 = yyinput()) != 'n' && c1 != 0)
{
goto loop;
}
}