I have a lex pattern file (test.l) where I want to recognize a pattern for an IPv4 address and an IPv6 address.
Currently I use a binary pattern notation for example
src -ip of 192.168.156.203 is to be written as
1 src-ip {11000000 10101000 10011100 11001011}
where ‘1’ is a tag that I use for classification.I want to extend this patter to include IPv4 address(dotted decimal) and IPv6 address (quad notation)
Currently my the relevant portion of my lexical analyser file (test.l) looks as below.
BINARY_PATTERN [ \t]*[ \t0-1\-\*]+[ \t]*
<S_src_ip>\{{BINARY_PATTERN}\} {
/*Some code here*/
}
I have slightly extended the code as below.
dec-octet [0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]
IPv4address {dec-octet}\.{dec-octet}\.{dec-octet}\.{dec-octet}
h16 [0-9A-Fa-f]{1,4}
ls32 {h16}:{h16}|{IPv4address}
IPv6address ({h16}:){6}{ls32}|
::({h16}:){5}{ls32}|
({h16})?::({h16}:){4}{ls32}|
(({h16}:){0,1}{h16})?::({h16}:){3}{ls32}|
(({h16}:){0,2}{h16})?::({h16}:){2}{ls32}|
(({h16}:){0,3}{h16})?::{h16}:{ls32}|
(({h16}:){0,4}{h16})?::{ls32}|
(({h16}:){0,5}{h16})?::{h16}|
(({h16}:){0,6}{h16})?::
<S_dst_ip>\{{BINARY_PATTERN}\}|\{{IPv4address}\}|\{{IPv6address}\} {
/*Some code here*/
}
to support IPv4 addresses and IPv6 addresses.when I try to compile the code
flex --header-file="test.h" test.l
test.l:665: unrecognized rule
The error is in the line "<S_dst_ip>\{{BINARY_PATTERN}\}|\{{IPv4address}\}|\{{IPv6address}\}"
Can someone point out to me what the error is or how it can be fixed?
Can someone point out what is the error.
The problem is probably related to your definition of
IPv6addressacross multiple lines — such definitions only go up to the end of the line, so the extra lines after that will cause probems. I would expect errors on those lines…