[antlr-interest] order tree nodes

Putrycz, Erik Erik.Putrycz at nrc-cnrc.gc.ca
Thu Apr 27 13:58:59 PDT 2006


I'm currently parsing a cobol file and I'd like to create a proper AST
for the records.

A record list looks like 

003634*01  RAREA.

003635     05  R00-999FIXED-AREA.

003636         10  RKEY-AREA                             PIC X(62).

003637         10  R906REC-TYPE                          PIC XX.

003638         10  R907BLKS                              PIC 9(4) COMP.

003639         10  CRTN-DT-TS-GRP.

003640           15  CRTN-CN                             PIC 9(2).

003641           15  CRTN-DT-TS.

 

What I'd like to do is have the node with 01 as root for the 05 and have
the 05 be the root of all the "10" nodes.

I tried to write something like

 

recordList

            : (recordCouple)+ { #recordList =
#([RECORD_LIST],#recordList);}

            ;

 

recordCouple

            :! (record record) => r1:record r2:record

                         {

                                    if (#r1 != null && #r2!= null &&
#r1.getText() != null && #r2.getText() != null) {

                                    int r1Val =
Integer.parseInt(#r1.getText());

                                    int r2Val =
Integer.parseInt(#r2.getText());

                                    if (r2Val > r1Val) {

                                                #recordCouple =
#(r1,r2);

                                    } 

                                    }

                        }

                        |record

            ;

 

unfortunately this is not working. 

If I put the "!" to ignore the default tree construction, how can I
return a list instead of a tree? In my code I miss an else alternative
to return (r1,r2) and not #(r1,r2).

Also, I don't believe that this rule will do the recursivity I need... I
rather need something like (r1:record r2:record) => record  but that
doesn't work.

Any suggestions or clues???

 

Thanks,

 

 

Erik Putrycz, Ph.D - Research Associate /
<mailto:erik.putrycz at nrc-cnrc.gc.ca> erik.putrycz at nrc-cnrc.gc.ca / (613)
990 0681

Institute for Information Technology - Software Engineering Group

National Research Council, Canada - Building M-50, 1200 Montreal Road

Ottawa, Ontario, CANADA K1A 0R6

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060427/94ed3e9b/attachment.html


More information about the antlr-interest mailing list