[antlr-interest] Re: Forcing creation of children in an AST t ree parser

mzukowski at yci.com mzukowski at yci.com
Thu Mar 4 09:22:28 PST 2004


That looks right.  This is lisp notation, where (A B C) means that A is the
root and B is the first child and C is B's sibling.  If 'activity' were not
a root then instead of 
( activity MERIS 1234:56 )
you would have got
activity MERIS 1234:56

Your tree parser rule would look like this:

activityTimeRange: #(ACTIVITY instrument timeExpr);

Monty

-----Original Message-----
From: Simon Kellett [mailto:skellett at anitesystems.de] 
Sent: Thursday, March 04, 2004 1:02 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Re: Forcing creation of children in an AST tree
parser

--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> Show us toStringList() for the result of rule:
> 
> activityTimeRange: ACTIVITY^ L_paren! INSTRUMENT Comma! timeExpr
> R_paren!;
> 
> It should be doing exactly what you want and I don't see why it
isn't.

My rule has changed slightly (instrument is now a subrule):

activityTimeRange: ACTIVITY^ L_paren! instrument Comma! timeExpr
R_paren!;
instrument: "MERIS" | "ASAR";

and I run it

Text i/p stream: activity (MERIS, 1234:56)
toStringList() gives: ( activity MERIS 1234:56 )

This is some of the generated Parser code;

else if ((LA(1) == ACTIVITY) && (LA(2) == L_paren) && (LA(3) ==
LITERAL_MERIS || LA(3) == LITERAL_ASAR) && (LA(4) == Comma) && (LA(5)
== ABS_TIME || LA(5) == REL_TIME || LA(5) == ORBIT_TIME)) {
			activityTimeRange();
			astFactory->addASTChild( currentAST, returnAST );

void LmpParser::activityTimeRange() {
...
tmp39_AST = astFactory->create(LT(1));
astFactory->makeASTRoot(currentAST, tmp39_AST);
match(ACTIVITY);
match(L_paren);
instrument();
astFactory->addASTChild( currentAST, returnAST );
match(Comma);
timeExpr();
astFactory->addASTChild( currentAST, returnAST );
match(R_paren);
activityTimeRange_AST = currentAST.root;
...

Thanks, Simon



 
Yahoo! Groups Links



 


 
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