[antlr-interest] Re: whitespaces in middle of rule

cintyram <cintyram at yahoo.com> cintyram at yahoo.com
Thu Jan 23 12:01:16 PST 2003


hi  
 i compiled only one line .. 
import java.    lang  . * ; 

and it is fine .. but your grammar accepts * as a substitute for a
package name, so i tried
import  java.*.lang.* ;  and it cribs ..

basically you might want to change your grammar to  have an optinal 
(DOT STAR) ?

 import_statement:
     "import" IDENT (DOT IDENT )* ( DOT STAR ) ?  SEMI
    ;


as for spaces within the  import statement , i dont know why you want
to force the user to write like that!

cheers
ram

--- In antlr-interest at yahoogroups.com, "William Lam <xeenman at y...>"
<xeenman at y...> wrote:
> good point and somewhat bad example, it is not illegal in java. 
> Thanks!
> 
> --- In antlr-interest at yahoogroups.com, Terence Parr <parrt at j...> 
> wrote:
> > 
> > On Wednesday, January 22, 2003, at 06:22 PM, William Lam 
> > <xeenman at y...> wrote:
> > 
> > > Sorry for this newbie question, but I wish to parse a grammar
> > > such as a Java import statement i.e.
> > >
> > > import aaaa.bbbb.cccc.*;
> > >
> > > so I set up a grammar similar to this
> > >
> > > import_statement:
> > >     "import" IDENT (DOT (IDENT | STAR))* SEMI
> > >     ;
> > >
> > > The problem is that the rule will validate statments filled with
> > > spaces, such as this
> > >
> > > import aaaa . bbbb . cccc . *;
> > >
> > > How do I make sure my import statements do not have any spaces?  I
> > > notice that the example under antlr/examples/java exhibit this
> > > problem.
> > 
> > Is it really illegal in Java?
> > 
> > Anyway, move it into the lexer if you need to.  Might be a 
> > context-sensitive problem though then matching ID.
> > 
> > Ter
> > --
> > Co-founder, http://www.jguru.com
> > Creator, ANTLR Parser Generator: http://www.antlr.org
> > Lecturer in Comp. Sci., University of San Francisco


 

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



More information about the antlr-interest mailing list