[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gnubol: problem 2.




These sample bison rules relate to resolving parenthesis on data references.  
I believe they solve the problem to the extent of coping with qualification, 
subscripting, and reference modification.  This is simple LA(k=1) code, 
nothing really special, except certain rules are fragmented (and there is a 
need to tidy things up at the end of recurses.

This code does _not_ relate to the arithmetic expression problem in the 
FUNCTION 
arguments. 

This code has not been tested; it is offered as a model of how to 
disambiguating rules by getting something onto the right side of a rule as a 
lookahead.

The rules start with a few arithmeitc rules.  In some positions a single data 
reference is allowed. In others a list of data items is permitted.  I have 
coded the presented rules the obvious, naive, way.  Anticipating good input.  
In the end this will not stand because we need
to see the input as it is and stay on out feet (specifically if a list occurs 
where a single item is 'required' we need the rule to look for that; and 
manually check in action code or in semantics).

simple : 
   MOVE ref_data TO ref_data_list_1_n
   {;}
 | MOVE CORR ref_data TO ref_data
   {;}

 | ADD ref_data_list_1_n  TO     ref_data_list_1_n_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}
 | ADD ref_data_list_1_n  GIVING ref_data_list_1_n_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}
 | ADD CORR ref_data      TO     ref_data_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}

 | SUB ref_data_list_1_n  FROM   ref_data_list_1_n_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}
 | SUB ref_data_list_1_n  FROM   ref_data
                          GIVING ref_data_list_1_n_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}
 | SUB CORR ref_data      FROM   ref_data_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}

 | MUL ref_data           BY     ref_data_list_1_n_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}
 | MUL ref_data           BY     ref_data
                          GIVING ref_data_list_1_n_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}


 | DIV ref_data           INTO   ref_data_list_1_n_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}

 | DIV ref_data           INTO   ref_data
                          GIVING ref_data_list_1_n_ROUNDED

   %prec PREC_SHIFT_LA_END_XYZ
   {;}
 | DIV ref_data           BY     ref_data
                          GIVING ref_data_list_1_n_ROUNDED
   %prec PREC_SHIFT_LA_END_XYZ
   {;}

 | DIV ref_data           BY     ref_data
                          GIVING ref_data_ROUNDED
                          REMAINDER ref_data
   %prec PREC_SHIFT_LA_END_XYZ
   {;}
 | DIV ref_data           INTO     ref_data
                          GIVING ref_data_ROUNDED
                          REMAINDER ref_data
   %prec PREC_SHIFT_LA_END_XYZ
   {;}

 | COMPUTE ref_data_list_1_n_ROUNDED EQUAL expr_arithmetic
   %prec PREC_SHIFT_LA_END_XYZ
   {;}

etcetera ..............................


/*  */
/* ref_data_list_1_n */
/* look for 1 to n data references */
/* %prec PREC_SHIFT_LA_SYMT_DATA */
ref_data_list_1_n : 
   ref_data %prec PREC_SHIFT_LA_SYMT_DATA
   { cnt = 1;}
 | ref_data_list_1_n  ref_data %prec PREC_SHIFT_LA_SYMT_DATA
   { cnt =+ 1;}
;

/* ROUNDED is optional on each ireration */
/* pardon the brutishness 
   some explications here to avoid epsilons in _opt subrules 
*/
ref_data_list_1_n_ROUNDED : 
   ref_data       
   %prec PREC_SHIFT_LA_SYMT_DATA
   { cnt = 1;}
 | ref_data ROUNDED 
   %prec PREC_SHIFT_LA_SYMT_DATA
   { cnt = 1;}
 | ref_data_list_1_n_ROUNDED  ref_data 
   %prec PREC_SHIFT_LA_SYMT_DATA
   { cnt =+ 1;}
 | ref_data_list_1_n_ROUNDED  ref_data ROUNDED 
   %prec PREC_SHIFT_LA_SYMT_DATA
   { cnt =+ 1;}
;



/* this is an optional ROUNDED reference */
ref_data_ROUNDED : 
   ref_data 
   {;}
 | ref_data ROUNDED 
   {;}
;

/*
  in this rule specific, explicated continuations
  provide a basis for disambiguation; the natural tendency
  would be to reference sub rules that have optional /* empty */
  alternates. That is the key: epsilons would compete in the 'continue'
  position, leading to r/r or s/r
*/
ref_data : 
   ref_data_simple_or_qual
   { /* simple */ ;}
 | ref_data_simple_or_qual PAR_OPEN ref_data PAR_CLOSE
   { /* subscripted */ ;}
 | ref_data_simple_or_qual PAR_OPEN ref_data COLON ref_data PAR_CLOSE
   { /* fully ref modified     */ ;}
 | ref_data_simple_or_qual PAR_OPEN ref_data COLON PAR_CLOSE
   { /* partially ref modified */ ;}
;

/* data references simple or qualified */
ref_data_simple_or_qual :
   ref_data_simple    
   { /* simple */ ;}
 | ref_data_qualified
   { /* qualified */ ;}
;

ref_data_simple : SYMT_DATA 
   {
   ;}
;

    
ref_data_qualified :
   ref_data_OFIN_recurse ref_data_simple
   { /* normal end */
     /* analyze last: 
        validate prev OFIN + simple */
   ;}
 | ref_data_OFIN_recurse %prec PREC_SHIFT_LA_SYMT_DATA
   { /* error OFIN recurse not ended with simple ref */
     /* this is tidy up work */
   ;}
;


ref_data_OFIN_recurse :
   ref_data_OFIN
   { /* first, do not analyze no precedant */
     /* this is a major opportunity also, 
        since only here in the recurse should a condition name occur
        (also FD/SD should _not_ occur here */
     */ 
   ;}
 | ref_data_OFIN_recurse  ref_data_OFIN
   { /* analyze each subsequent of OFIN segment:
        validate prev OFIN this "
     */
     /* opprotunity: condition names should not occur here, n >= 2 */
   ;}
;


/* the crux of the matter is the  */
ref_data_OFIN : 
   SYMT_DATA OFIN
   {;}
;

***********
I am using a set of precedences derived from a non alphabetic list of tokens 
and
dummy %prec variables.  All shiftable items, must not only have a superior 
precedence, they must be defined %right !


Best Wishes
Bob Rayhawk
RKRayhawk@aol.com

--
This message was sent through the gnu-cobol mailing list.  To remove yourself
from this mailing list, send a message to majordomo@lusars.net with the
words "unsubscribe gnu-cobol" in the message body.  For more information on
the GNU COBOL project, send mail to gnu-cobol-owner@lusars.net.