[antlr-interest] adding "version" option to ANTLR grammars

Gary R. Van Sickle g.r.vansickle at att.net
Tue Jan 20 04:22:09 PST 2009


> From:  Johannes Luber
> 
> > At 22:27 20/01/2009, Johannes Luber wrote:
> >  >> > options {
> >  >> > 	language = ...;
> >  >> > 	version = "3.1.1";
> >  >> > }
> >  >
> >  >I just thought about an improvement: ANTLR should warn 
> the user, if  
> > >the version isn't identical to the one of the tool. That 
> way people  
> > >not only see a potential issue, but are more inclined to 
> update the  
> > >string.
> > 
> > I agree with both of those.
> 
> Another improvement would be to allow a comma-separated list. 
> With it one can record all versions of ANTLR, with which the 
> grammar works without any modifications.

The trouble with that is that it forces the user to predict the future.
Maybe it will work with the next fifty versions, which may only have changes
which don't affect the ultimate interpretation, such as bug fixes, speed
improvements, and the like, but there's no way to specify that.  

The only way this sort of thing works is for the source file to declare
"this is the standard I was written to".  It is then up to the interpreters,
past, present, and future, to either modify their interpretation to match
that of the specified standard (i.e. future ANTLR versions "degrading" their
interpretation) or simply bail (e.g. ANTLR 3.1.2 tries to read a grammar
that says its written to the ANTLR 8.5.6 standard, which it of course has no
idea what that even is, so it can't possibly interpret it).

A halfway solution used by some (autoconf comes to mind) is to list a
minimum required version of the interpreter.  It's a bit of a fine
distinction, but this tends to be problematic in the opposite direction: it
forces the developer of the interpreter (i.e. Terence et al) to never break
backward compatability - i.e. always have one foot in the past.  It also
doesn't actually tell anyone anything about the source; does
"requires_ANTLR_version = 3.1.1" mean it's using the "^(" or the "#("
rewrite syntax?  No way to know until you hit the first one, so why bother
with the "requires" at all?

> Once one does a 
> backwards-incompatible upgrade (be it bugfix, changed ANTLR 
> behaviour or the use of a new feature), the list is cleared. 

How do you do that once your grammar leaves your PC?  Your customer decides
to upgrade his ANTLR install and now your program won't compile.

> And if someone is unsure if a grammar change makes things 
> incompatible, he has to check merely the latest given version.
> 

-- 
Gary R. Van Sickle



More information about the antlr-interest mailing list