aboutsummaryrefslogtreecommitdiff
path: root/scanner.l
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-12-04 19:00:46 -0800
committerGuy Harris <guy@alum.mit.edu>2015-12-04 19:00:46 -0800
commit5823e2382c11cb9cdbe895c7e34b045a25c3bd78 (patch)
treeb05d73b2755a22d00fca2e46dcec80c08b3fff6f /scanner.l
parent720b9a33921bbc017ef39bd57dc25a8e9ce9535c (diff)
downloadlibpcap-5823e2382c11cb9cdbe895c7e34b045a25c3bd78.tar.gz
Generate a reentrant lexical analyzer and parser.
This doesn't make pcap_compile() completely reentrant and thread-safe, but it's a significant step along the way. Get rid of some stuff left over from when we supported classic Lex.
Diffstat (limited to 'scanner.l')
-rw-r--r--scanner.l129
1 files changed, 59 insertions, 70 deletions
diff --git a/scanner.l b/scanner.l
index 6b46fbe3..451f86b4 100644
--- a/scanner.l
+++ b/scanner.l
@@ -6,10 +6,27 @@
}
/*
+ * We want a reentrant scanner.
+ */
+%option reentrant
+
+/*
+ * We don't use input, so don't generate code for it.
+ */
+%option noinput
+
+/*
+ * We don't use unput, so don't generate code for it.
+ */
+%option nounput
+
+/*
* We don't read from the terminal.
*/
%option never-interactive
+%option bison-bridge
+
%{
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -53,6 +70,15 @@
#include "gencode.h"
+#include "grammar.h"
+
+/*
+ * Earlier versions of Flex dsn't declare these, so we declare them
+ * ourselves to squelch warnings.
+ */
+int pcap_get_column(yyscan_t);
+void pcap_set_column(int, yyscan_t);
+
#ifdef INET6
#ifdef _WIN32
@@ -101,20 +127,6 @@
static int stoi(char *);
static inline int xdtoi(int);
-#ifdef FLEX_SCANNER
-#define YY_NO_INPUT
-#define YY_NO_UNPUT
-static YY_BUFFER_STATE in_buffer;
-#else
-static const char *in_buffer;
-
-#undef getc
-#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
-#endif
-
-#define yylval pcap_lval
-extern YYSTYPE yylval;
-
%}
N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
@@ -357,17 +369,17 @@ hsls return HSLS;
"==" return '=';
"<<" return LSH;
">>" return RSH;
-${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
- if (yylval.e == NULL)
+${B} { yylval->e = pcap_ether_aton(((char *)yytext)+1);
+ if (yylval->e == NULL)
bpf_error("malloc");
return AID; }
-{MAC} { yylval.e = pcap_ether_aton((char *)yytext);
- if (yylval.e == NULL)
+{MAC} { yylval->e = pcap_ether_aton((char *)yytext);
+ if (yylval->e == NULL)
bpf_error("malloc");
return EID; }
-{N} { yylval.i = stoi((char *)yytext); return NUM; }
+{N} { yylval->i = stoi((char *)yytext); return NUM; }
({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
- yylval.s = sdup((char *)yytext); return HID; }
+ yylval->s = sdup((char *)yytext); return HID; }
{V6} {
#ifdef INET6
struct addrinfo hints, *res;
@@ -378,67 +390,44 @@ ${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
bpf_error("bogus IPv6 address %s", yytext);
else {
freeaddrinfo(res);
- yylval.s = sdup((char *)yytext); return HID6;
+ yylval->s = sdup((char *)yytext); return HID6;
}
#else
bpf_error("IPv6 address %s not supported", yytext);
#endif /*INET6*/
}
{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
-icmptype { yylval.i = 0; return NUM; }
-icmpcode { yylval.i = 1; return NUM; }
-icmp-echoreply { yylval.i = 0; return NUM; }
-icmp-unreach { yylval.i = 3; return NUM; }
-icmp-sourcequench { yylval.i = 4; return NUM; }
-icmp-redirect { yylval.i = 5; return NUM; }
-icmp-echo { yylval.i = 8; return NUM; }
-icmp-routeradvert { yylval.i = 9; return NUM; }
-icmp-routersolicit { yylval.i = 10; return NUM; }
-icmp-timxceed { yylval.i = 11; return NUM; }
-icmp-paramprob { yylval.i = 12; return NUM; }
-icmp-tstamp { yylval.i = 13; return NUM; }
-icmp-tstampreply { yylval.i = 14; return NUM; }
-icmp-ireq { yylval.i = 15; return NUM; }
-icmp-ireqreply { yylval.i = 16; return NUM; }
-icmp-maskreq { yylval.i = 17; return NUM; }
-icmp-maskreply { yylval.i = 18; return NUM; }
-tcpflags { yylval.i = 13; return NUM; }
-tcp-fin { yylval.i = 0x01; return NUM; }
-tcp-syn { yylval.i = 0x02; return NUM; }
-tcp-rst { yylval.i = 0x04; return NUM; }
-tcp-push { yylval.i = 0x08; return NUM; }
-tcp-ack { yylval.i = 0x10; return NUM; }
-tcp-urg { yylval.i = 0x20; return NUM; }
+icmptype { yylval->i = 0; return NUM; }
+icmpcode { yylval->i = 1; return NUM; }
+icmp-echoreply { yylval->i = 0; return NUM; }
+icmp-unreach { yylval->i = 3; return NUM; }
+icmp-sourcequench { yylval->i = 4; return NUM; }
+icmp-redirect { yylval->i = 5; return NUM; }
+icmp-echo { yylval->i = 8; return NUM; }
+icmp-routeradvert { yylval->i = 9; return NUM; }
+icmp-routersolicit { yylval->i = 10; return NUM; }
+icmp-timxceed { yylval->i = 11; return NUM; }
+icmp-paramprob { yylval->i = 12; return NUM; }
+icmp-tstamp { yylval->i = 13; return NUM; }
+icmp-tstampreply { yylval->i = 14; return NUM; }
+icmp-ireq { yylval->i = 15; return NUM; }
+icmp-ireqreply { yylval->i = 16; return NUM; }
+icmp-maskreq { yylval->i = 17; return NUM; }
+icmp-maskreply { yylval->i = 18; return NUM; }
+tcpflags { yylval->i = 13; return NUM; }
+tcp-fin { yylval->i = 0x01; return NUM; }
+tcp-syn { yylval->i = 0x02; return NUM; }
+tcp-rst { yylval->i = 0x04; return NUM; }
+tcp-push { yylval->i = 0x08; return NUM; }
+tcp-ack { yylval->i = 0x10; return NUM; }
+tcp-urg { yylval->i = 0x20; return NUM; }
[A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
- yylval.s = sdup((char *)yytext); return ID; }
-"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
+ yylval->s = sdup((char *)yytext); return ID; }
+"\\"[^ !()\n\t]+ { yylval->s = sdup((char *)yytext + 1); return ID; }
[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
bpf_error("illegal token: %s", yytext); }
. { bpf_error("illegal char '%c'", *yytext); }
%%
-void
-lex_init(buf)
- const char *buf;
-{
-#ifdef FLEX_SCANNER
- in_buffer = yy_scan_string(buf);
-#else
- in_buffer = buf;
-#endif
-}
-
-/*
- * Do any cleanup necessary after parsing.
- */
-void
-lex_cleanup()
-{
-#ifdef FLEX_SCANNER
- if (in_buffer != NULL)
- yy_delete_buffer(in_buffer);
- in_buffer = NULL;
-#endif
-}
/*
* Also define a yywrap. Note that if we're using flex, it will