[antlr-interest] advocacy of C++ support in ANTLR 3.x

Tomas Potrusil potrto at centrum.cz
Fri Mar 28 05:43:12 PDT 2008


Oh yes, I know. I've already made a prototype implementation of a part of
the grammar based on the idea I presented bellow (atom returns [OurNode*
result] etc.). It is working but it is a little bit clumsy and I cannot use
the resulting AST for a tree parsing - of course, I'm creating my own AST.

 

I've been thinking about the new tree adapter (I was talking about bellow)
and probably you are true,  few C++ wrappers could do the work. But there is
one inconvenience - there is not an "abstract" tree yet. The most abstract
tree is ANTLR3_BASE_TREE_struct which contains children vector and other
attributes. The ANTLR3_TREE_struct with only pointers to functions
(something like a Java interface) would suit my needs better. Our existing
AST nodes solve the storage already. Could you do it, please?

 

Another problem is safety. When somebody call
ANTLR3_BASE_TREE_struct::addChild(pANTLR3_BASE_TREE tree) for example, I
must trust him that the tree argument is really the tree he is calling. I
cannot write dynamic_cast<MyTreeWrapper>(tree->super). This cannot be solved
in the current C-based system.

 

Tom

 

From: Jim Idle

 

ANTLR 3.1 C target can now incorporate C++ code directly into the grammar
and so can easily call your existing C++ code. All you do is compile the C
output file as C++ (or rename it to .cpp perhaps). 

Can you try using that and let me know if you think that there is anything
that you could do if the runtime was C++ that you can't do right now? I
don't really think that there will be.

You need to get the latest 3.1 snapshot from the downloads page and use the
ANTLR Tool hjar in there. Then build the ANTLR 3.1 C runtime from the tar.gz
in the dist director under the runtime/C directory in the snapshot. 3 or 4
people have successfully integrated their C++ code with the C target now and
I think you will have similar success :-)

Jim

 

-----



Hallo,

 

I'm new to the list. I'm trying to use ANTLR for generating a SQL parser
because our current parser doesn't support Unicode input - it was generated
by Lex/Yacc. We use C++ and we have our own complex AST that is used by a
SQL engine already... So my idea is to write a tree adapter that would
create our existing AST nodes (they would just inherit ANTLR tree
interface).

 

And here comes a problem that ANTLR 3.x doesn't contain support for "pure"
C++ implementation. I've just found Jim Idle's "promise":

 

> Later I may well produce a complete C++ implementation from scratch,

> however, at this point I am not sure that it buys you anything. Please

> let me know if there are things you cannot do with the system as it

> stands (other than access the tokens and so on using C++ objects, which

> will be done later). 

 

I know that the problem could be solved with the current system somehow, but
it would be probably very ugly. So yes, complete C++ implementation will buy
us something! Or we can use ANTLR 2.x.

 

Right now we will probably try to build the AST by hand:

 

atom returns [OurNode* result]

@init { $result = NULL; }

:              NUMBER

                {

                               std::string str((char*)$NUMBER.text->chars,
$NUMBER.text->len);

                               $result = new OurNumberNode(str);

                };

 

Or do you have some other ideas?

 

Thanks

 

Tom

 

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


More information about the antlr-interest mailing list