-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhlex.l
60 lines (47 loc) · 1.1 KB
/
hlex.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
D [0-9]
L [a-zA-Z_]
OS [ ]*
%{
#include <stdio.h>
#include <string.h>
#include "hparse.h"
static void comment(void);
%}
%%
"#".* { }
"//".* { }
"/*" { comment(); }
"__"{L}+ { return(ID); }
"__"{L}+{OS}*"("+{L}({L}|{D})*")"+ { return(ID); }
{L}({L}|{D})* {
yylval.s = strdup(yytext);
return ID;
}
"," { return(','); }
"*" { return('*'); }
"(" { return('('); }
")" { return(')'); }
";" { return(';'); }
[ \t\v\n\f] { }
. { }
%%
int
yywrap(void)
{
return(1);
}
static void
comment(void)
{
char c, c1;
loop:
while ((c = input()) != '*' && c != 0)
putchar(c);
if ((c1 = input()) != '/' && c != 0)
{
unput(c1);
goto loop;
}
if (c != 0)
putchar(c1);
}