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

Tom Moog tmoog at polhode.com
Fri Oct 26 10:56:58 PDT 2001



You can get one character of lookahead by using zzchar
(C mode) or (ch in C++ mode ? don't have my manuals with
me).  Thus you can put in your lex action routine:

	<< if (! telephoneChar(ch)) {mode(START); } >>

On Fri, 26 Oct 2001 cela_vei at yahoo.com wrote:

> 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)
> 
> sip_url: LEFTBRACE SIP COLON ...... RIGHTBRACE
> 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
> Cela.
> 
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 
> 


 

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



More information about the antlr-interest mailing list