[antlr-interest] Literals table empty

Boulanger Jean-Louis jean-louis.boulanger at hds.utc.fr
Sat Nov 15 02:00:56 PST 2003


Hello,

 I have the same pb in a big grammar where parser and lexer are in the same
file. I use import and export clause and I don't find a solution. I supposes
that is a little bug. This pb appear also when you consruct a new grammar by
inheritance.

BJL 

Selon mzukowski at yci.com:

> When I copy and paste this into one .g file it works.  The problem probably
> has to do with the fact that your are exporting the vocab from the lexer and
> importing into the parser.  Look at the docs on import/export vocab stuff,
> but I think if you want them in separate files you will have to do some
> extra work to keep the vocabularies in sync.  
> 
> Has anyone else done this and have some advice?
> 
> If you don't have other constraints then keeping the lexer and parser in the
> same .g file will certainly make it work.
> 
> Monty
> 
> -----Original Message-----
> From: yahamkon [mailto:Vladimir.Konstantinov at rogers.com] 
> Sent: Friday, November 14, 2003 1:10 PM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Literals table empty
> 
> Thanks again, but the grammar doesn't recognize the Literal as such, 
> it matches an returns an Identifier instead:
> 
> /////
> class ExpressionParser extends Parser;
> 
> options {
> 	importVocab=Expression;             
> 	buildAST=true;
> }
> 
> calc: (ID|fun) END ;
> fun: "min"|"max" ;
> 
> class ExpressionLexer extends Lexer ;
> 
> options{exportVocab=Expression;}
> 
> END: ';';
> 
> ID options {testLiterals=true;}: 
> 	('a'..'z'|'A'..'Z'|'_'|'$') 
> ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'$')*
> ;
> /////
> 
> I looked up the generated code - the Lexer class doesn't populate the 
> literals table at all (although "min" and "max" are defined as 
> LITERAL_xxx tokens in the respective zzzTokenTypes.java file).
> 
> What am I missing now, I compared the options from the java.g file 
> and my example (regarding literals), the java geherated lexer has its 
> literals table populated, mine is not being populated in the 
> generated Lexer class ?
> 
> Any ideas? TIA
> 
> 
> 
> --- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> > No, you need a lexer rule something like 
> > ID:
> > options {testLiterals=true;}
> > ('a'..'z' | 'A'..'Z')+
> > ;
> > 
> > Monty
> > 
> > -----Original Message-----
> > From: yahamkon [mailto:Vladimir.Konstantinov at r...] 
> > Sent: Thursday, November 13, 2003 11:16 AM
> > To: antlr-interest at yahoogroups.com
> > Subject: [antlr-interest] Re: help with literals
> > 
> > Thanks for the fast response!
> > 
> > >> See docs on literals and any example grammar with an ID rule.
> > 
> > I've looked in the docs, the "java.g" grammar, also searched the 
> > archives but things aren't getting clearer.
> > 
> > > Yes, you need a rule that will test it's result against the 
> defined
> > > literals. 
> > 
> > Isn't "calc" such a rule? To put it defferently, if I had a grammar 
> > that specifies a single rule recognising a single literal how would 
> > that look like (that's what I had in mind sending the example 
> anyway)?
> > 
> > 
> > 
> > 
> > 
> > > 
> > > Monty
> > > 
> > > -----Original Message-----
> > > From: VLADIMIR KONSTANTINOV [mailto:Vladimir.Konstantinov at r...] 
> > > Sent: Thursday, November 13, 2003 11:03 AM
> > > To: antlr-interest at yahoogroups.com
> > > Subject: [antlr-interest] help with literals
> > > 
> > > 
> > > I want to specify literals ("min", "max", "sum" etc) in my 
> grammar.
> > >  
> > > I am getting :
> > >  line 1:1: unexpected char: 'm'
> > >  line 1:2: unexpected char: 'i'
> > >  line 1:3: unexpected char: 'n'
> > > when testing with the following expression: "min;" 
> > >  
> > > This a stripped down version of my grammar:
> > >  
> > > ///
> > > class ExpressionParser extends Parser;
> > > options { importVocab=Expression; }
> > > calc: fun END;
> > > fun: "min";
> > >  
> > > class ExpressionLexer extends Lexer ;
> > > options{ exportVocab=Expression;}
> > > END: ';'
> > > ///
> > >  
> > > I am missing something very basic, but can't figure it out myself.
> > >  
> > > Thanks in advance.
> > > 
> > > 
> > >  
> > > 
> > > 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/
> 
> 
>  
> 
> 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/ 
> 




-------------------------------------------------
Laboratoire Heudiasyc. UMR CNRS 6599
http://www.hds.utc.fr

 

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




More information about the antlr-interest mailing list