[antlr-interest] does the third argument work, for AST node constructor ?

Ric Klaren klaren at cs.utwente.nl
Wed Feb 12 07:57:07 PST 2003


Hi,

On Wed, Feb 12, 2003 at 03:36:28PM +0100, Anthony Brenelière wrote:
> I use the C++ language as language output.
>
> Is there any backup solution to change the token type of a created token
> type ?

Use setText/setType on the generated AST element depending on what you want
to change. e.g #entity->setType(RENTO) (or YourTokenTypes::RENTO)

> entity! // (supplier WHERE name="Telys"):client
> 	:	(COLON)? a:entityComponent ( COLON! b:entity )?
> 		{ #entity = #( #[RENTO, "<entity>"], #a, #b, #[RENTC,
> "</entity>"]); }
> ;

I think I never ported that syntax to C++ mode. Information of those #[]
constructors uses one of the most ugly and frail hacks inside antlrs
action-parser to generator interface. There is also a argument against
fiddling with the returned AST type on spots all over the code (e.g. you
might destroy the mapping the AST factory expects of ID to type, which
would not be that practical).

> tokens {
> 	...
> 	RENTO<AST=NodeAST>; RENTC<AST=NodeAST>;
> 	...
> }
>
> .. but in the program, the returned node is ttype = RENTO and uses a
> CommonAST Node.

This setup should work (and is the recomended setup in my opinion). 

Is NodeAST correctly derived? Have you set up your ASTFactory correctly?

Be aware that the Reference counting used for the AST's in ANTLR defeats
quite a few nice polymorphism tricks that you'd normally expect to be
working. (Yes, I'm no fan of heterogeneous AST's in C++ mode)

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
 Why don't we just invite them to dinner and massacre them all when they're
  drunk? You heard the man. There's seven hundred thousand of them. Ah? ..
           So it'd have to be something simple with pasta, then.
                 From: Interesting Times by Terry Pratchet


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list