[antlr-interest] A newbie's question

Aki Niimura akineko at gmail.com
Tue Mar 17 20:07:57 PDT 2009


Hello Michael,

Thank you for your prompt response.
I'm trying to write a C Interpreter (with special hooks).
I originally tried to use existing open-source C Interpreter, such as CINT.
But I decided to re-invent a wheel because I need to insert special hooks.

I would like to use a grammar file, C.g, that is available on the ANTLR web
site.
The updated version of C.g, which is verified with Python target is also
available from FishEye.
I created (1) and (2) using the C.g.

I prefer three step approach as it separates parser grammar and application
specific actions.

The C.g grammar is fairly complex and written by somebody else.
So, creating (3) Tree grammar is not an easy task for me.

In such sense, I agree with your suggestion inserting my application
specific stuff into the C.g and not to create (3) step.
The code would look very messy but it is probably easier for me to figure
out where to insert.

Again, what I thought was the (2) step should able to create a summary of
the grammar that should be used in the (3) step.
It would be nice if the future ANTLR has such feature if that is not
possible with the current release.

I will try to find more in the ANTLR web site and mailing list archive.

Thanks,
Aki-


On Tue, Mar 17, 2009 at 6:58 PM, Michael Bedward
<michael.bedward at gmail.com>wrote:

> Hi,
>
> First decide if you really need step 3 (the tree parser).  If you want
> to parse some program / script and then perform evaluation multiple
> times, or you want to work on the AST to optimize execution or make it
> easier to do translation etc. then the answer is yes.  But if you just
> want to parse a program / script and run it once then it's optional -
> you could just embed actions in the parser grammar in step 2.
>
> In my own apps I do more or less copy the parser grammar (minus
> actions and AST rewrite rules) and use this as the basis for the tree
> grammar.  If the grammar is not huge this is practical, but if it is,
> or if there are multiple tree walking stages (ie. step 4, step 5 etc
> each of which generates a new AST) then it can get tricky.
>
> There was a recent discussion of this here...
> http://www.antlr.org/pipermail/antlr-interest/2009-February/032799.html
>
> Hope this helps
> Michael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090317/fb4f37ce/attachment.html 


More information about the antlr-interest mailing list