[antlr-interest] newbie problems

Jim Idle jimi at temporal-wave.com
Sat Jun 23 09:10:55 PDT 2007


This really needs to be:

 

fragment

LETTER: ('a'..'z' | 'A'..'Z') ;

 

Your original lexer was returning a token for NEWLINE but you had not
specified any way to deal with that token in the grammar.

 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Gevik Babakhani
Sent: Saturday, June 23, 2007 5:47 AM
To: 'Anders Hessellund'; 'antlr'
Subject: Re: [antlr-interest] newbie problems

 

Hi,

 

Here is a fix for your grammar. These things are well explained in the
ANTLR book.

 

grammar Test; 

 

site    :  page+

            ;

 

page    :            'PAGE' ID

            ;

 

ID         :           LETTER+

            ;

 

TEXT    :    LETTER ( LETTER )*

            ;

    

LETTER            :           'a'..'z'|'A'..'Z' 

            ;

 

    

WS       :           (' ' | '\t' | '\r' | '\n')+ {$channel=HIDDEN;}

            ;

 

 

________________________________

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Anders Hessellund
Sent: Saturday, June 23, 2007 12:50 PM
To: antlr
Subject: [antlr-interest] newbie problems

 

Hi,

I am sorry about the newbie question but neither google nor this list
seems to have any obvious answers to my question :)

I have just started with antlr by defining this little grammar:

grammar Web;

site    :    page+ 
    ;

page    :    'PAGE' ID
    ;

ID    :    LETTER+
    ;

TEXT    :    LETTER ( LETTER | WS )*
    ;
    
LETTER    :    'a'..'z'|'A'..'Z' 
    ;

NEWLINE    :    '\r'? '\n'
    ;

WS    :    (' ' | '\t' | '\n' | '\r' )+ { skip(); }
    ;


Then I generate my lexer and parser tools and feed them the follow input
file 

	 

	PAGE helloWorld


I get the following strange error. Could someone please explain why?? 

line 0:-1 required (...)+ loop did not match anything at input '<EOF>' 



-- Anders 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070623/aaa8b012/attachment.html 


More information about the antlr-interest mailing list