-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildlex.pl
executable file
·56 lines (42 loc) · 939 Bytes
/
buildlex.pl
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
#!/usr/bin/perl -w
# definitions
print <<EOF;
%{
#include <cstdint>
#include <iostream>
uint64_t pos = 0;
#define YY_SKIP_YYWRAP
#undef YY_BUF_SIZE
#define YY_BUF_SIZE 16777216
#define YY_READ_BUF_SIZE 16777216
#define YY_INPUT(buf,result,max_size) \\
errno=0; \\
while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\
{ \\
if( errno != EINTR) \\
{ \\
YY_FATAL_ERROR( "input in flex scanner failed" ); \\
break; \\
} \\
errno=0; \\
clearerr(yyin); \\
}\\
std::cerr << pos << std::endl; \\
\\
%}
/* %option 8bit main nodefault nounput noyylineno noyymore noyywrap warn */
%option 8bit main pointer batch noyymore noyywrap case-insensitive
%%
EOF
# rules
while (<ARGV>) {
chomp;
print <<"EOF";
$_ std::cout << "@{[$.-1]}@[" << pos << ',' << (pos + yyleng) << "): " << yytext << '\\n'; pos += yyleng;
EOF
}
# catchall rule
print <<EOF;
.|\\n ++pos; /* eat unmatched chars */
%%
EOF