[antlr-interest] RE: Treebuilding ....

mzukowski at yci.com mzukowski at yci.com
Fri Apr 4 08:39:53 PST 2003


OK, now I kinda see the problem.  Thing is, you didn't post your tree parser
rules so I can't tell why you are having problems in your tree parser.  For
the first example, is "END" a statement that statement_list can match?

OK, now, in this rule you turned tree building off and you are creating a
root called stlist with no children because #statement_list is empty since
you turned off tree building, just what I would expect to happen.  You
almost got the idiom right, just turn tree building back on for the rule.

statement_list! 
        : ( (statement_line (EOL!)+ )+ ) 
        { #statement_list = #(#[STLIST,"stlist"], #statement_list); } 
        ; 

Make it 
statement_list 
        : ( (statement_line (EOL!)+ )+ ) 
        { #statement_list = #(#[STLIST,"stlist"], #statement_list); } 
        ; 

By the way there is a shorthand for #current_rule, which is ## 

statement_list
        : ( (statement_line (EOL!)+ )+ ) 
        { ## = #(#[STLIST,"stlist"], ##); } 
        ; 
Monty

-----Original Message-----
From: Anthony Youngman [mailto:Anthony.Youngman at ECA-International.com]
Sent: Friday, April 04, 2003 7:32 AM
To: 'antlr-interest at yahoogroups.com'
Subject: [antlr-interest] RE: Treebuilding ....


Carrying on from my last problem... now I've got rid of the
non-determinism... 
If my parser contains the definition: 
        statement_line : (statement ( SEMI! statement)* ) ; 
        statement_list : ( (statement_line (EOL!)+ )+ ) ; 
I seem to get the tree I expect namely 
        ( PROGRAM SHELL (LOOP (PRINT...) (INPUT ...) (PRINT ...)  ...)
(PRINT ...) END ) null 
when I print out the tree using 
        System.out.println( "printing AST"); 
        AST result = parser.getAST(); 
        System.out.println(result.toStringList()); 
BUT the treeparser chokes on it. It's expecting "PROGRAM" ID statement_list
"END". It seems to me it's expecting a single "statement_list", and when fed
the expanded list as above it chokes because it gets a LOOP. So I changed
the definition of statement_list to
statement_list! 
        : ( (statement_line (EOL!)+ )+ ) 
        { #statement_list = #(#[STLIST,"stlist"], #statement_list); } 
        ; 
which now gives me 
        ( PROGRAM SHELL stlist END ) null 
when I print the tree. The treeparser chokes on this, because it seems my
statement_list has become a root with no sibs or children or whatever - my
loop, print etc have got lost :-( Apologies if this seems simple - I seem to
have been asking question after question on the list, but I've been tearing
my hair out of the syntax of "statement_list!". Is it right? And if so, why
doesn't "toStringList()" traverse it?
Cheers, 
Wol 


This transmission is intended for the named recipient only. It may contain
private and confidential information. If this has come to you in error you
must not act on anything disclosed in it, nor must you copy it, modify it,
disseminate it in any way, or show it to anyone. Please e-mail the sender to
inform us of the transmission error or telephone ECA International
immediately and delete the e-mail from your information system.
Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911
7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1
212 582 2333.

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 

 

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




More information about the antlr-interest mailing list