[antlr-interest] Newbie Question

John Green greenj at ix.netcom.com
Fri Oct 5 18:45:33 PDT 2001


Hi Michael,

I won't try to give any opinions or advice about tree walkers, because my
experience with them is limited to one tree walker that I built for
evaluating some expressions (basically a mini-interpreter).

> Am I correct in assuming that this attempting to create a node with a root
of 'NDeclaration' so that this is easier to identify later on?

Yup. I think those are called "synthetic nodes" in the Antlr docs (if memory
serves).

> For my application, it seems quite reasonable to identify certain key
structural pieces and do things like the above.  If I start doing this, I
would like to protect for the possibility of having both Java and C++ tree
walkers.  Is it, in general, possible to build a parser grammar with markups
and so on without having to write any target language specific actions?  I
assume this would be the goal if somebody were trying to develop a language
neutral grammar?

It depends. Adding synthetic nodes, and other syntactic type things, can be
done with Antlr features, and then you get to stay language neutral. For my
parser though, I needed a lot of semantic productions, so there's a lot of
C++ mixed into my grammar.

For whatever it's worth, here's what I've done:

The parser that I built has been used to build a configurable "lint" tool,
which people also use for checking that code follows their own style
guidelines. We don't use Antlr tree-walkers for that. I have built the
parser into a DLL, and provided an API into that. The programmers can now
use their native tongue (a 4GL) and the API to build their own tools for
walking through the tree and ensuring that their code follows their own
style guidelines.

I've provided an API to the "hidden tokens", so that they can enforce rules
like: every function declaration must be commented.

Well, anyway, that's one way of doing it. If I had been doing an in-house
project, rather than letting other programmers build tools based on the
parser, then I may well have used Antlr tree-walkers instead.

Regards,
John
www.joanju.com


  -----Original Message-----
  From: Tiller, Michael (M.M.) [mailto:mtiller at ford.com]
  Sent: Saturday, October 06, 2001 5:14 AM
  To: 'antlr-interest at yahoogroups.com'
  Subject: [antlr-interest] Newbie Question


  I'm still trying to understand how to make the best use of ANTLR.  I'd
like to describe a simple scenario (that I am currently faced with) and ask
a few questions about it...

  As a side project, I would like to build a tool that will check some
source code against some style guidelines that we have internally.  Toward
this end, I have developed a lexer and parser already that can parse the
language that I am interested in.  So far, so good.

  At this point, it seems to me that I have the pieces for turning the
characters into tokens and then tokens into productions.  Now what I want to
do is walk the tree that gets generated by the parser.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20011006/5a0b931d/attachment.html


More information about the antlr-interest mailing list