[antlr-interest] Simple Question

Ric Klaren klaren at cs.utwente.nl
Mon Jun 16 08:24:52 PDT 2003


Hi,

On Mon, Jun 16, 2003 at 10:58:43AM -0400, Tiller, Michael (M.M.) wrote:
> I wanted to point something out about this response...
>
> I think you need to be careful here.  As I pointed out in a question posted
> to this list (but never responded to), this does not work in certain cases
> (at least I couldn't get it to work).  The idea of having a line like:
>
> ##->setSomeAttribu(sumthin);
>
> is to invoke a method on the custom AST node.  BUT, ANTLR will not generate
> an appropriate initializeASTFactory in some cases (see my previous note
> titled "Simple Question") and this would then fail.

Good for reminding me. The original was still in my inbox.

On Fri, Jun 13, 2003 at 11:32:31AM -0400, Tiller, Michael (M.M.) wrote:
> As usual, I'm struggling with the best way to structure my AST processing.
> I followed the example from the GCC parser and create my own nodes, e.g.:
>
> modelica_file
>     : (within_clause)? (("final")? class_definition SEMI!)* EOF!
>         { ## = #([FILE, "FILE"], ##); }
>     ;
>
> Note, specifically, the use of "#([FILE, "FILE"], ...)"
>
> Now I'd like to use my own AST class for this node so I can associate
> additional "meta" information (i.e. data that gets generated as I make a
> few passes over the tree).  My personal preference is to have specific
> classes for each AST node.  I know you can do it in a generic way, but it
> just doesn't feel right to me.
>
> OK, enough on that, here is the issue.  My token section looks like this:
>
> tokens {
>     FILE<AST=FileNode>; DECLARATION; DEFINITION; FUNCTION_CALL; TYPE;
>    ...
> }
>
> Note the "File<AST=FileNode>..." part.
>
> I would have thought that the combination of defining this special token
> (and the custom AST that goes with it) along with the tree construction
> shorthand would have created an appropriate "initialFactory" method for my
> parser that would have mapped a FILE token to a FileNode.  This doesn't
> happen.  It appears that ANTLR doesn't do this automatically for these
> "synthetic" tokens (ones that do not originate from the lexer).
>
> So, is my assessment correct (i.e. this feature doesn't work with synthetic
> nodes...of which I have *many*).  Or am I doing something wrong?

Questions:

1) Which codegen? Java? C++? C#?
2) If C++ mode:
   - How do you set up/initalize the AST factories ?
   - Also related to initializations of lexer->parser->treeparser
     initialization and subsequent calls of
     initializeASTFactory calls ?
   - Which imaginary nodes do you define where?
   - You are building the lexer/parser/treeparsers in the right order?
   - Can you construct a small example demonstrating the problem?
3) If other mode: I'm innocent ;) (I hope :) )
   - seriously... also try to answer those questions under 2 :) Might be
     some differences in Java/C# mode. Ter did some stuff a bit different
     for Java than I did them in C++

On a more serious note, the stuff that garbles together the items for the
initializeFactory calls is pretty fragile. Not many people use the
heterogeneous AST stuff in C++ mode as well (is my impression, I'd expect
more questions/problems with it then).

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  Wit is cultured insolence. --- Aristotle

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list