[antlr-interest] C++ as a target - FAQ questions...
Ric Klaren
klaren at cs.utwente.nl
Wed Sep 22 08:55:44 PDT 2004
Hi,
On Wed, Sep 22, 2004 at 11:19:14AM -0400, Bryan Ewbank wrote:
> I've just started to use ANTLR, and seem to be in the minority because I
> have C++ as my target language, rather than java. I've been able to compile
> an executable with my language it in (hurrah!), but am having a hard time
> sorting out what is Java and what is ANTLR in a specific file.
>
> Is there a place where someone that knows compilers well (theory and
> application) can find information on what is available in the actions and
> surrounding code for a C++ target? The LL(k) versus LALR stuff wasn't much
> of a problem - though lexing REAL versus INTEGER is annoying - but figuring
> out the class hierarchy and what magic incantation to use to get what I want
> seems to be hard.
>
> For example, I know that C++ uses "->" in most(?) places where the Java uses
> "."; likewise, "::" instead of "." seemed to resolve some other problems.
The "->" appears for all the reference counted stuff.
- Tokens (RefToken)
- AST nodes (RefAST)
- LexerSharedInputState
- ParserSharedInputState
For all places where the dots appear for namespace qualification the C++
parts use "::".
In general all the action code is pure C++. Though the filtering that is
done on the code inside the action code to translate the tree
building/referencing is somewhat crude at times (lacking in error feedback,
but that's a general antlr problem)
You also can generate documentation of the support library with doxygen.
In case of doubt it really helps to look at the generated code. But that's
a general idiom for antlr.
> Now I'm at one that stumped me. In the "Debugging and Testing Grammars"
> discussion on the web, there are several calls to "super.<xxyyzz>"; however,
> I don't know the name of the superclass to use when translating this to C++,
> so can't precisely implement this on my own.
You mean you're trying to port the ParseTreeDebugParser stuff from java to
C++ ? If you get it working I'd welcome the files then I can include them
in the C++ support library.
To get to the question if I look at for instance ParseTreeDebugParser:
Some of the constructors would be ported to:
public:
ParseTreeDebugParser( int k )
: LLkParser(k)
{
}
public:
ParseTreeDebugParser( TokenBuffer& tokenBuf, int k )
: LLkParser(tokenBuf,k)
{
}
public:
ParseTreeDebugParser( TokenStream& lexer, int k )
: LLkParser(lexer,k)
{
}
It's basically chaining the constructors to the superclass.
Add the necessary ugly ANTLR_USE_NAMESPACE(antlr) macro's for the antlr
classes btw.
The super.match( .. ) things would translate to LLkParser::match( .. )
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755 ----
-----+++++*****************************************************+++++++++-------
Chaos often breeds life, when order breeds habit.
--- Henry B. Adams, The Education of Henry Adams
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list