Subject: [SIP] SIP parser: newbie

From: [email-masked]
Date: Fri, 4 Aug 2000 13:04:52 +0530 (IST)

The recent mails recommending flex/bison, lex/yacc etc., for the 
SIP parser have confused me a bit.

I'd like to know the `granularity' of the tokenizer/parser split.

For instance,
---------------------------------------------------------------
sip_msg : request | response
        ;

request : request_line header_list CRLF
        ;

request_line : METHOD WORD SIP_VERSION CRLF
        {
                /* hand-decode the request uri */
            if (! decode_request_uri($2)) {
                /* handle error somehow */
            }
        }
        ;

where WORD is a token denoting any sequence of characters 
without whitespace, cr-lf chars, and the comma.

For example, its lex specification may be:

[^ ,\t\r\n] {
    return WORD;
}
---------------------------------------------------------------

My question is because I found it hard to parse, say, the sip-url 
using the flex/bison route. 
Since yacc and bison generate a LALR(1) parser, I had conflicts 
while trying to parse:

    hostname = *(domainlabel ".") toplabel ["."]
    domainlabel = alphanum | ...
    toplabel = alpha | ...

The conflict was because bison couldn't distinguish between 
domainlabel & toplabel with its one-token lookahead. So that ended 
in a reduce-reduce conflict!

I'd like to know if this is the right approach:
1. tokenize the input string into words (of course, some words are
   easily distinguishable, like methods, Accept, To, From etc.,)
2. hand-verify the words that yacc couldn't handle (like urls).

Or is it possible to make yacc handle everything by 
tweaking the grammar?

Any pointers would be appreciated.
Thanks very much.

_______________________________________________
SIP mailing list
[email-masked]
http://lists.bell-labs.com/mailman/listinfo/sip