[antlr-interest] C target issues: winsock.h and duptree()

craig.williams at free.fr craig.williams at free.fr
Thu Jan 8 11:27:39 PST 2009


First of all thanks to Terence, Jim et. al. for the new version of Antlr. I last
used v.2.6 with the C++ target about 3 years ago, and appreciate the great
improvements you have made - the book is good too.
I have upgraded my old grammar and tree walker code, so most of my C++ code now
works fine with the new Antlr version.

I have a couple of problems - I hope you have time to point me in the right
direction.

I am also using the ACE libraries in my project, which prefer the winsock2.h
instead of the old winsock.h header. To get around the incompatibility, I put
this workaround in antlr3defs.h

#if defined (_WINSOCKAPI_)
#   include <winsock2.h>
#else
#   include <winsock.h>
#endif /* _WINSOCKAPI_ */

Maybe you have a better idea?

In previous version of Antlr, I was able to copy ASTs while walking the tree and
later in the program, re walk these ASTs independently to perform different
actions:

e.g. in the first walk of the tree, copy the part of the tree of interest:
   ListAST = _t; // walk some more tree, possibly modifying it
   ...
   antlr::RefAST ra = ASTfact.dupList(ListAST);

later in the program, the copied AST was walked a second time to perform
evaluation functions,

passing the copied AST as a parameter:

list = TreeWalker.evalList (ListAST);

In the new version, I can see the equivalent tree copy function:

pANTLR3_BASE_TREE pAST	= (pANTLR3_BASE_TREE)$s->dupTree($s);

but I suspect it may not be the right way to go.

I feel I should be able to reuse the context structure ...Ctx_struct immediately
after the 1st tree walk, and rewalk parts of the tree with the function pointers
of this struct.  Do you have any recommendations on the best way to achieve
this?

Thanks in advance.

Craig


More information about the antlr-interest mailing list