bnfc

How to correctly use coercions such that no parenthesis are needed?


Why does the following grammar does not recognize nat -> nat but does recognize (nat -> nat) and how can I fix that?

 TNat . Typ4 ::= "nat" ;                                                        
 TVoid . Typ4 ::= "<>" ;    
 TProd . Typ3 ::= SumType;                                
 TProd . Typ2 ::= Typ2 "*" Typ3;                                                
 TArrow . Typ1 ::= Typ1 "->" Typ2;                                              
 coercions Typ 4;      

Solution

  • Inverting the order of declaration fixed the issue

    TArrow . Typ ::= Typ "->" Typ1;
    TSum . Typ1 ::= SumType;
    TProd . Typ2 ::= Typ2 "*" Typ3;
    TNat . Typ3 ::= "nat" ;
    TVoid . Typ3 ::= "<>" ;
    coercions Typ 3;