Pergunta

I'm new to lex programming and I'm trying fix this piece of relatively old code. If I try compile this Lex compiler stuck around processing pattern ip6addr. Looks like it stucks in endless loop. When I try compile individual parts of address, it will finish successfully. I don't know what is wrong. These patterns are from Flex Manual

Next little problem is around line starting with #.*$ { }. Lex gives me warning about dangerous trailing context. I read in manual that these are patterns where the ending of the first part of the rule matches the beginning of the second part. But I don't see any other conflicting rule.

%{

int params_linecnt = 1;

%}

number  ([[:digit:]]{-}[0])[[:digit:]]*
dec-octet   [0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]
ip4addr     {dec-octet}\.{dec-octet}\.{dec-octet}\.{dec-octet}

hexdigit    ([a-f]|[A-F]|[0-9])
addr1       {hexdigit}{1,4}":"({hexdigit}{1,4}":")*(":"{hexdigit}{1,4})+
addr2       {hexdigit}{1,4}(":"{hexdigit}{1,4})*"::"
addr3       ({hexdigit}{1,4}":"){7}{hexdigit}{1,4}

h16     [0-9A-Fa-f]{1,4}
ls32        {h16}:{h16}|{ip4addr}

ip6addr1 ({h16}:){6}{ls32}
ip6addr2 ::({h16}:){5}{ls32}
ip6addr3 ({h16})?::({h16}:){4}{ls32}
ip6addr4 (({h16}:){0,1}{h16})?::({h16}:){3}{ls32}
ip6addr5 (({h16}:){0,2}{h16})?::({h16}:){2}{ls32}
ip6addr6 (({h16}:){0,3}{h16})?::{h16}:{ls32}
ip6addr7 (({h16}:){0,4}{h16})?::{ls32}
ip6addr8 (({h16}:){0,5}{h16})?::{h16}
ip6addr9 (({h16}:){0,6}{h16})?::

ip6addr {ip6addr1}|{ip6addr2}|{ip6addr3}|{ip6addr4}|{ip6addr5}|{ip6addr6}|{ip6addr7}|{ip6addr8}|{ip6addr9}

%s STRING

%%

<STRING>[^ \t\n;]+ {
    params_lval.string = strdup(yytext);
    BEGIN 0;
    return T_STRING;
}

[Nn]amed    { BEGIN STRING; return T_NAMED; }
[Aa]ddress  { return T_ADDR; }
[Uu]se      { BEGIN STRING; return T_USE; }
snd_cga_params  { BEGIN STRING; return T_DERFILE; }
snd_cga_priv    { BEGIN STRING; return T_KEYFILE; }
snd_cga_sec { return T_SEC; }
[Ii]nterface    { BEGIN STRING; return T_INTERFACE; }
snd_sig_meth    { BEGIN STRING; return T_SIGMETH; }

[\t ]+          { }
"{"|"}"|";"     { return *yytext; }
#.*$            { }
\n          { params_linecnt++;}

{number} {
    params_lval.num = atoi(yytext); return T_NUMBER;
}

{ip6addr} {
    struct in6_addr addr;
    int i;

    i = inet_pton(AF_INET6, yytext, &addr);
    if (i < 0) {
        applog(LOG_ERR, "Error parsing address %s (line %d): %s",
            yytext, params_linecnt, strerror(errno));
        return T_BAD_TOKEN;
    }

    params_lval.addr6 = addr;
    return T_IPV6_ADDR;
}
Foi útil?

Solução

I've just updated my Arch Linux and flex to version 2.5.39 and suddenly all problems disappear. Maybe it was bug in flex in Arch repository. For now it is fixed for me.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top