[antlr-interest] Separation of specification and code

David Wigg wiggjd at lsbu.ac.uk
Mon Mar 7 14:01:21 PST 2005

I am using subclassing to separate application code from the
parser code in our C/C++ parser, CPP_parser.g which is
available from the antlr website.

I have called the demonstration application code MyCode.cpp
and you could see how this was done for C++.

Basically this is done by including a call to the subclassed
functions in the required places in the antlr grammar definition.

I think this a useful facility because it keeps the code,
statements and, in particular, the data, separate, enabling
different people to work on the two parts at the same time.

David Wigg
London South Bank University

Message: 2
Date: Mon, 07 Mar 2005 11:43:26 -0500
From: Monty Zukowski <monty at codetransform.com>
Subject: Re: [antlr-interest] Separation of specification and
To: antlr-interest at antlr.org
Message-ID: <422C84AE.8040605 at codetransform.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Ken Weinert wrote:

 > I've been an antlr advocate since it was pccts (Hi Terence
:) but I've
 > not really had occasion to use it much since then.
 > My boss stopped by today with a question that I'm relaying
here as I'm
 > really not familiar enough with the mechanics to know if
 > supports this mode of operation.
 > What he'd like is to be able to keep the specification
clean and the
 > code separate. He mentioned Grammatica which uses the EBNF
to produce
 > a parser, but you implement the actions by extending the
class for
 > each leaf in the generated code.
 > Have I made myself clear? Is this something that antlr
 > Pointers to where I can easily resolve this are as (if not
 > welcome as direct answers.
 > Thanks for any information.

Well, are you talking just about making a parser or are you
about a translator?

Somebody wrote a "literate programming" system for ANTLR which
is all
about keeping the action code separated from the .g file.  A
web search
should turn it up, it may be on the antlr.org file sharing
page as well.

If you are talking about a translator, grammar subclassing is
approach.  http://www.codetransform.com/fun_with_antlr.html
has a few
details about managing an eight pass translator.


More information about the antlr-interest mailing list