[antlr-interest] ANTLR274: Small functional extension proposal: synonym

Francis ANDRE francis.andre at easynet.fr
Tue Sep 7 12:26:32 PDT 2004


> Hi.  Well, that's pretty specialized.  Further, all you have to do is
> add them to the hashtable of literals with the same token type and
> it'll just work. :)

Yes, it is what I have done for now

But the problem is the maintenance and the lisibility of a grammar
maintained by a third party. IMHO, it would better to express the fact that
a token has more than one lexeme or textual representaiton in the grammar
itself than in a additional derivative generated lexer. (Just for you to get
my point, my grammar has more than 260 tokens with at least 20 synonyms)

Make the evidence evident whenever possible is a quite good rule when
programming!

Regards

FA

PS:  JavaCC is providing such synonym descriptions in the grammar

----- Original Message ----- 
From: "Terence Parr" <parrt at cs.usfca.edu>
To: <antlr-interest at yahoogroups.com>
Sent: Tuesday, September 07, 2004 7:50 PM
Subject: Re: [antlr-interest] ANTLR274: Small functional extension proposal:
synonym


> Hi.  Well, that's pretty specialized.  Further, all you have to do is
> add them to the hashtable of literals with the same token type and
> it'll just work. :)
>
> Ter
> On Sep 7, 2004, at 4:51 AM, Francis ANDRE wrote:
>
> > Hi Terence & all
> >
> > I would like to propose you the following extension to manage simply
> > synonyms. One could define in the tokens section definition some
> > lexemes that abstract themself to a same token like :
> >
> > tokens {
> > YES = "YES" | "Y" | "OK" | "YEAP" | "DA";
> > }
> >
> > Since all literals above should returns the same YES token value,
> > IMHO, it should be enough to generate in the Lexer something like:
> >
> > void Lexer::initLiterals()
> > {
> > literals["YES"] = 3;
> > literals["Y"]= 3;
> > literals["OK"] = 3;
> > literals["YEAP"] 3;
> > literals["DA"] = 3;
> > }
> >
> >
> > In fact, this will avoid to have a grammar rule that specifies all
> > the alternatives to get a YES which is really the case!!
> >
> >
> > What do you think about??
> >
> > Cheers
> >
> > FA
> >
> >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> --
> CS Professor & Grad Director, University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
> Cofounder, http://www.knowspam.net enjoy email again!
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list