[antlr-interest] Is ANTLR the right tool for the job?

Wigg, J D wiggjd at lsbu.ac.uk
Fri Jan 5 04:51:23 PST 2007


Alan,
 
As the latest author of the C++ parser you are looking at I would
suggest you make quite sure the software you are used to (JavaCC?)
won't work for the code you have first.
 
If not, I think CPP_parser is as up to date as I can get it, so see if
it parses your code without any problems next.
 
If this is OK, then you need to consider other possible limitations of
CPP_parser.
 
1. It does not produce an AST. I haven't felt the need to do this. If
you produce an AST you still have to insert your own code in the
appropriate places to produce the output you need so you might as well
include your code (for output) in the parser. This is quite easy to do
using sub-classed code called MyCode as described in the read me file.
 
2. It does not have a feature for automatically writing all the source
code to a new file but I suppose this should be possible somewhere.
 
3. When writing the source code (amended) to a new file extra work
will be required to include the comments (since these are ignored by
the parser). Again, this should not be too difficult to do.
 
4. Replacement of code. Difficulty will depend how extensive this is
and how the changes match the grammar.
 
Hope this helps. FYI I am away on holiday from Sunday 7 January to
Sunday 21 January.
 
I would be interested to hear of any advantages you see in producing
and working from an AST.
 
I would be interested to hear how you get on.
 
David.
 
Message extracted from antlr-interest Digest, Vol 26, Issue 7
 
Message: 1
Date: Thu, 04 Jan 2007 16:40:09 +0000
From: Alan Larkin <nobrow at eircom.net>
Subject: [antlr-interest] Is ANTLR the right tool for the job?
To: antlr-interest at antlr.org
Message-ID: <459D2DE9.4050808 at eircom.net>
Content-Type: text/plain; charset=ISO-8859-1

I need to modify some C++ code, performing tasks such as replacing
primitive numeric variables with new objects and converting arithmetic
expressions to different forms.

I would like very much to do this using JavaCC as I have had very
positive experiences using it on Java in the past. By first passing
the
grammar file through Java Tree Builder (JTB) the resulting parser will
return an abstract syntax tree for the inputted code, which supports
the
visitor design pattern. I could then write small visitors to locate
and
replace the relevant sections of code, reformat the code using a
formatting visitor, and finally dump the new code to file.

Unfortunately the C++ grammars for JavaCC are woefully substandard (10
years old!). ANTLR looks like it has a better C++ grammar but I am
unsure if it can be used to satisfy the above objectives.

Can the list please advise on whether or not ANTLR is suitable for
this
task and possibly direct me to some useful examples of such processes?

Many thanks,
Alan.





This e-mail message may be confidential and is intended only for the use of the individual(s) to whom it is addressed.  It may contain information which is or may be confidential, non-public or legally privileged. Please do not disseminate or distribute this message other than to its intended recipient without permission of the author. You should not copy it or use it for any purpose nor disclose its contents to any other person. If you have received this message in error, please notify me by email immediately and delete the original message and all copies in your computer systems.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070105/3f300889/attachment.html 


More information about the antlr-interest mailing list