[antlr-interest] C++ beginner questions
David Maxwell
david at crlf.net
Thu Sep 29 12:46:20 PDT 2005
Hi list,
I've just started using Antlr, and while I appreciate the concepts, I'm
finding it very frustrating.
Any pointers people have that would help with the following issues would
be great:
1) Is there a list of Java -> C++ equivalent methods?
i.e.
$setType(Token.SKIP);
--> _ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP;
Almost all of the tutorials target Java, and it's often not clear to me
how to get the same effect in C++.
2) Are there any examples targetting C++ that do NOT use the AST
funcionality?
The AST tools sound great - but right now I just want a lex/yacc
replacement with multi-token lookahead. The types of things you want to
do in the parsing stage are quite different if you're not building ASTs,
and I can't find examples to get me started. (Yes, I've looked in
examples/cpp/*)
For example, I can't find even a single instance of using a token's
text, in a C++ example. Reading the generated C++ doesn't make it any
clearer either.
I've labelled tokens in the _Paser_ and used ->getText() there, but in
the _Lexer_ it doesn't work for me. The label ends up becoming a goto
target label, and not an object with a getText() method. Even with gdb
on the generated program, I can't find any variable that holds the
token's text.
3) The documentation plays a bit fast and loose with the term 'antlr'.
i.e. "Antlr keeps track of the column position of tokens for you" -
Well, no, but the _Lexer_ antlr produces does so. Now, it's not a great
example, because we could have an argument about what column position
should mean in the context of the Parser - but regardless, it would be
nice to have a list of which Functions are applicable in which contexts.
Using getColumn() in the Parser led to some wasted time for me, before
I thought about the Parser/Lexer split in the .g file for a bit.
4) Is there any equivalent to the Lex/Yacc documentation 'How to resolve
shift/reduce conflicts' - for how to address lexical nondeterminisms in
antlr?
For example, I've noticed that rule order in the Lexer DOES matter, but
I can't find any documentation about how to order rules to get the
desired results. I've just been following 'most specific first', but
I'd appreciate a more precise answer.
I'll probably have more questions as I do more, but that's enough for
now ;-)
Thanks,
David
More information about the antlr-interest
mailing list