[antlr-interest] Re: How to put back a token read by lexer

cela_vei at yahoo.com cela_vei at yahoo.com
Fri Oct 26 07:14:04 PDT 2001

Here is my problem

My input string is

Contact: tel:+1-212-345-8902, <sip:xyz at matt.com> \r\n
Contact: tel:456-235;phone-context=201 \r\n
Contact: <sip:abc at cold.com>

#lexclass START

#token CONTACT "Contact"
#token COLON ":"
#token COMMA ","
#token CRLF "\r\n"
#token TEL "tel" < mode(TELMODE); >

.... < more tokens  > ....

#lexcalss TELMODE
#token DIGIT "[0-9]"
#token DASH "\-"
#token PLUS "+"

..... < more tokens in TELMODE> .....

As soon as I see the "tel" I want to switch the lexer to the TELMODE
lexer. There is no terminator token to end the "tel: .....".
As soon as see a token that is not in the TELMODE I want to switch
back to START mode. One such token above is a COMMA (",") or a CRLF
(\r\n"). I am having trouble switching back to START mode because I
can switch only after the COMMA or CRLF is cosumed. As part of my 
parse rule I want to use the COMMA. Here is my parse grammer.

contact_header: CONTACT COLON contact_header_value 
                (COMMA contact_header_value)*

contact_header_value: (sip_url | tel_url)

tel_url: { PLUS } (DIGIT | DASH)+

When the tel_url rule is over the contact_header rule does not get the
COMMA token.

Is there any way to achieve this? BTW, I am still using the 1.33MR29
release of Antlr.

Thanks for the help


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list