The grammar for sip is part of the rfcs. You will have to dig some to get
at all the referenced rfcs (from rfc 2543) to construct a complete
grammar.
Lex an yacc grammars for sip are a nontrivial affair because sip has no
reserved tokens. For example, here is a legal SIP url:
sip:sip:[EMAIL PROTECTED]
This is also a legal sip URL
sip:[EMAIL PROTECTED]
the first sip: is a token but the second is a username.
Compiler compilers such as yacc are good for dealing with programming
languages with reserved keywords such as c or java where, for example,
"if" is a token and cannot be a legal variable name.
To parse sip headers with such tools, you have two choices:
1. Define multiple token sets in the lexical analyser and switch between
token sets in a context dependent fashion
2. Construct an attributed syntax tree where there are no tokens
(i.e. only identifiers) and then walk the syntax tree resolving the tokens
in a context dependent fashion.
You can define multiple token sets in lex and switch between them.
However, the token sets have to be disjoint. The more the number of token
sets, the more hacky your parser. Further, it is a nontrivial matter to
come up with the right partition.
The second approach is equally error prone because you are essentially
using the parser to just extract the tree structure of the header and
doing all the attributions "by hand"
You may also find that the sip grammar does not fit neatly into the
LALR(1) framework (yacc only works for lalr(1))
So the best bet for SIP is to either parse by hand or use a flexible
parser generator (I would avoid yacc).
<plug>
Among the parser generators I examined, I found antlr to be the most
flexible (i.e. it allows you to become as hacky as you want if you know
what you are doing). Using antlr, I constructed a parser for SIP headers
and have made it available for download. If you are interested, visit
http://is2.antd.nist.gov/proj/iptel
Currently, I generate java code but if you work at it, antlr can be made
to generate c++ (I have no plans to do a c++ version myself at this time).
</plug>
Regards
Ranga.
On Fri, 9 Feb 2001, Shashidhara. G. K . wrote:
> Hi,
>
> IF anybody has a copy of SIP grammar. Please mail it to me.
> Also indicate where I can get Lex and Yacc versions of it.
>
> Thanks,
> Bye.
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
> _______________________________________________
> Sip-implementors mailing list
> [EMAIL PROTECTED]
> http://lists.cs.columbia.edu/mailman/listinfo/sip-implementors
>
--
hM.Ranganathan
NIST Advanced Networking Technologies Group,
100 Bureau Drive, Stop 8920, Gaithersburg, MD 20899.
Tel: 301 975 3664 Fax: 301 590 0932
_______________________________________________
Sip-implementors mailing list
[EMAIL PROTECTED]
http://lists.cs.columbia.edu/mailman/listinfo/sip-implementors