[antlr-interest] C Target: what to use instead of CommonTree whenwriting tree grammars, antlr 3.0

Jim Idle jimi at temporal-wave.com
Sat Jul 7 20:01:50 PDT 2007


Tree walking and everything is all implemented (it better be or my own
in production parsers are imaginary ;-).

 

However, you don't say if this snippet is in your tree generating
parser, or your tree parser, nor supply the error messages?

 

Once again, the example projects should rescue you. While we could do
with a more comprehensive tree walking example, but in the tree parser
for the strangely named 'treeparser' example, you will find:

 

decl : ^(DECL type declarator)

 

       // label.start, label.start, label.text

       {

         printf("int \%s\n", $declarator.text->chars);

       }

     ;

 

The node types in the C runtime are always the built in ones as these
contain a pointer within them that should poitn to any super structure
you might add. SO you are always passing around pANTLR3_BASE_TREE,
within wich is a super pointer to pANTLR3_COMMON_TREE, within which is a
superpointer which you are free to point to your own even larger
structure. Because this is a bit of a pain in C, there is also a custom
void * pointer in the pANTLR3_COMMON_TREE which you can just hijack to
point to whatever you like (you must free it).

 

Perhaps there is some problem referencing .text on a TOKEN? For error
reports I need as much detail as possible if you could oblige J

 

Jim

 

 

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Hardy, Stephen
Sent: Saturday, July 07, 2007 12:17 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] C Target: what to use instead of CommonTree
whenwriting tree grammars, antlr 3.0

 

Jim,

 

I can't get my head around this.  Have you implemented the necessary
infrastructure for using tree walkers with the C target?  I would like
to use templates, however they are not yet available for C.  So, I am
happy to use printf's and other hacks to get going.  The trouble is, I
can't relate the java examples in the book to how to do this in C, and
there are no examples.  For example, I am writing

 

type_id:

            : IDENTIFIER { printf("\%s ", $IDENTIFIER.text->chars); }

            ;

 

But it obviously isn't that simple since I get errors all over the
place.  Also, what is the correct ASTLabelType incantation to use in the
options section?  It isn't CommonTree, that's for sure.

 

Regards,

SJH

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070707/ac9ffa8a/attachment-0001.html 


More information about the antlr-interest mailing list