[antlr-interest] Puzzled by leading dot

Alexey Demakov demakov at ispras.ru
Tue Mar 15 08:15:24 PST 2005


Just define it as usual token.

DOTSE : ".SE" ;

Tokens section is for changing token type in special cases
(keyword is special case of identifier).
But DOTSE is not special case of IDENT because
IDENT can't start with '.'

Regards,
Alexey

P.S. May be "=" should be in lexer too? :)

-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com


----- Original Message ----- 
From: "Juergen Weber" <weberjn at yahoo.com>
To: <antlr-interest at antlr.org>
Sent: Tuesday, March 15, 2005 6:58 PM
Subject: [antlr-interest] Puzzled by leading dot


>    
> Hi,
> 
> I want to parse lines of the form
> 
> .SE DATE = '03.02.2005';.SE TIME = '20:17'            
>    
> 
> (basically a key value format, the .SE is to be
> ignored).
> 
> If I parse the input with the grammar below, I got
> this error message:
> 
> Exception in thread "main" line 1:1: unexpected char:
> '.'
> 
> How could I specify a keyword with a leading dot?
> 
> Thanks for your help,
> Juergen
> 
> 
> 
> 
> class MyParser extends Parser;
> 
> 
> line
> : item (SEMI item)*
> ;
> 
> item 
> : DOTSE IDENT "=" STRING_LITERAL
> ;
> 
>   
> 
> class MyLexer extends Lexer;
> 
> tokens {
>         DOTSE=".SE";
> }
> 
> 
> IDENT
> : ('a'..'z'|'A'..'Z'|'_')
> ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
> ;
> 
> 
> 
> STRING_LITERAL 
> :
> '\'' 
> (~'\'')* 
> '\'' 
> ;
> 
> 
> SEMI: ';'
> ;




More information about the antlr-interest mailing list