[comp.windows.x] uwm doesn't recognize control|shift|meta + FIX

casey@lll-crg.llnl.gov (Casey Leedom) (12/07/88)

  Uwm will recognize key expressions of <empty>, <key>, or <key> | <key>,
but won't recognize <key> | <key> | <key>.  The fix is trivial.  The
person who put together uwm's gram.y just wasn't familiar with specifying
LALR(1) grammars.  I've changed the explicit enumerations of syntax into a
recursive form that doesn't have any restrictions on the number of keys
that can be in a key expression.

Casey

-----
*** /usr/local/src/X.V11R3/clients/uwm/gram.y-dist	Wed Sep 21 12:14:31 1988
--- /usr/local/src/X.V11R3/clients/uwm/gram.y	Tue Dec  6 15:08:28 1988
***************
*** 159,166 ****
  			                yyerror(msg);
  			            }
  			            if ($3 == C_MENUMAP) {
! 			                bindtofunc
! ($1, bkmask, cmask, menu_name);
  			            } else yyerror("illegal construct");
  			            break;
  			        case IsMenu:
--- 159,165 ----
  			                yyerror(msg);
  			            }
  			            if ($3 == C_MENUMAP) {
! 			                bindtofunc($1, bkmask, cmask, menu_name);
  			            } else yyerror("illegal construct");
  			            break;
  			        case IsMenu:
***************
*** 228,234 ****
  			{ $$ = 0; }
  	|	kmask
  			{ $$ = $1; }
! 	|	kmask '|' kmask
  			{ $$ = $1 | $3; }
  	;
  
--- 227,233 ----
  			{ $$ = 0; }
  	|	kmask
  			{ $$ = $1; }
! 	|	kmask '|' keyexpr
  			{ $$ = $1 | $3; }
  	;
  
***************
*** 236,245 ****
  			{ $$ = ROOT | WINDOW | ICON; }
  	|	contmask
  			{ $$ = $1; }
! 	|	contmask '|' contmask
  			{ $$ = $1 | $3; }
- 	|	contmask '|' contmask '|' contmask
- 			{ $$ = $1 | $3 | $5; }
  	;
  
  buttexpr:	buttmodexpr
--- 235,242 ----
  			{ $$ = ROOT | WINDOW | ICON; }
  	|	contmask
  			{ $$ = $1; }
! 	|	contmask '|' contexpr
  			{ $$ = $1 | $3; }
  	;
  
  buttexpr:	buttmodexpr

casey@lll-crg.llnl.gov (Casey Leedom) (12/07/88)

From: casey@lll-crg.llnl.gov (Casey Leedom)
| 
|   Uwm will recognize key expressions of <empty>, <key>, or <key> | <key>,
| but won't recognize <key> | <key> | <key>.  The fix is trivial.  The
| person who put together uwm's gram.y just wasn't familiar with specifying
| LALR(1) grammars.  I've changed the explicit enumerations of syntax into a
| recursive form that doesn't have any restrictions on the number of keys
| that can be in a key expression.

  Well this just goes to show that I shouldn't be making postings while
I'm sick.  The patch I distributed for uwm yesterday does indeed solve
the described problem, however it's tacky and allows weird and asymmetric
constructs.

  Yacc, like many parser generators for LALR(1) grammars, generates
better parsers if recursive specifications are left recursive (it also
changes the associativity of the grammar, but since ``|'' is a commutative
operator that doesn't matter).  Also, the patch I gave yesterday allows
things like ``<key> |'' but doesn't allow ``| <key>''.  The first will
work correctly since the right hand side evaluates to zero, but looks
weird.  The fact that the equally weird second version isn't allowed is
just plain gross if we're going to allow the first.

  This new fix uses left recursion and doesn't allow either ``<key> |''
or ``| <key>''.  (If you like the latter two syntaxes, it's easy to set
up the grammer for that - I just figured no one would want those.)  Sorry
for the noise created by my earlier posting.

Casey

P.S.  Awm uses a grammer specification almost exactly like my earlier fix
    and so ``suffers'' the same problems described here.

-----
*** gram.y-dist	Wed Sep 21 12:14:31 1988
--- gram.y	Wed Dec  7 06:32:36 1988
***************
*** 79,85 ****
--- 79,87 ----
  %type <ival> keyword
  %type <ival> compexpr
  %type <ival> keyexpr
+ %type <ival> kexpr1
  %type <ival> kmask
+ %type <ival> cexpr1
  %type <ival> contexpr
  %type <ival> contmask
  %type <ival> buttmodexpr
***************
*** 159,166 ****
  			                yyerror(msg);
  			            }
  			            if ($3 == C_MENUMAP) {
! 			                bindtofunc
! ($1, bkmask, cmask, menu_name);
  			            } else yyerror("illegal construct");
  			            break;
  			        case IsMenu:
--- 161,167 ----
  			                yyerror(msg);
  			            }
  			            if ($3 == C_MENUMAP) {
! 			                bindtofunc($1, bkmask, cmask, menu_name);
  			            } else yyerror("illegal construct");
  			            break;
  			        case IsMenu:
***************
*** 226,245 ****
  
  keyexpr:	/* empty */
  			{ $$ = 0; }
! 	|	kmask
  			{ $$ = $1; }
! 	|	kmask '|' kmask
  			{ $$ = $1 | $3; }
  	;
  
  contexpr:	/* empty */
  			{ $$ = ROOT | WINDOW | ICON; }
! 	|	contmask
  			{ $$ = $1; }
! 	|	contmask '|' contmask
  			{ $$ = $1 | $3; }
- 	|	contmask '|' contmask '|' contmask
- 			{ $$ = $1 | $3 | $5; }
  	;
  
  buttexpr:	buttmodexpr
--- 227,250 ----
  
  keyexpr:	/* empty */
  			{ $$ = 0; }
! 	|	kexpr1
  			{ $$ = $1; }
! 	;
! kexpr1:		kmask
! 			{ $$ = $1; }
! 	|	kexpr1 '|' kmask
  			{ $$ = $1 | $3; }
  	;
  
  contexpr:	/* empty */
  			{ $$ = ROOT | WINDOW | ICON; }
! 	|	cexpr1
  			{ $$ = $1; }
! 	;
! cexpr1:		contmask
! 			{ $$ = $1; }
! 	|	cexpr1 '|' contmask
  			{ $$ = $1 | $3; }
  	;
  
  buttexpr:	buttmodexpr