[antlr-interest] order tree nodes

Olivier Dragon dragonoe at mcmaster.ca
Thu Apr 27 14:58:25 PDT 2006


Hi Erik,

I think it would be better not to use "couples" because your tree won't
be right.

I don't know COBOL very much but from your example I assume that those
numbers just keep on increasing. In that case you could keep track of
the current parent and have your rule look at each record individually
comparing it to the parent. If it's larger, do parent.addChild(record),
if it's the same do parent.setNextSibling(record); parent = record;

Does that help?

-Olivier

On Thu, Apr 27, 2006 at 04:58:59PM -0400, Putrycz, Erik wrote:
> 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
> 
>  
> 

-- 
          __-/|    ? ?     |\-__
     __--/  /  \   (^^)   /  \  \--__
  _-/   /   /  /\ / ( )  /\  \   \   \-_
 /  /   /  /  /  (   ^^ ~  \  \  \   \  \
 / Oli Dragon    ( dragonoe at mcmaster.ca \
/  B.Eng. Sfwr   ( dragon.homelinux.org  \
/  /  /    /__--_ (   ) __--__\    \  \  \
|  /  /  _/        \_ \_       \_  \  \  |
 \/  / _/            \_ \_       \_ \  \/
  \_/ /                -\_\        \ \_/
    \/                    )         \/
                        *~
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20060427/e752c459/attachment.bin


More information about the antlr-interest mailing list