Home
 

Disambiguating Features

Disambiguating Features

Scanner

For flex (see the section called scanner.l in Appendix B) we have the following situation.

":="       {ckout();
        TOKEN(ASGTK, 0);
         return ASGTK;}
":"             {ckout();
                TOKEN(COLONTK, 0);
                return COLONTK;}
"="             {ckout();
                TOKEN(EQTK, 0);
                 return EQTK;}


This is ambiguous, because := can be resolved as ASGTK or COLONTK EQTK. The "longest-match" rule applies, which resolves this to be an ASGTK.

Parser

The following precedence rules are used. Only the latter two are needed to disambiguate the grammar. The former two are for documentation only.

%nonassoc ASSIGNTK
%nonassoc LTTK LETK EQTK NETK GETK GTTK
%left PLUSTK MINUSTK
%left STARTK SLASHTK


These are needed because the expression grammar, which is shown below, is ambiguous.

Expr:
    Expr PLUSTK Expr
    | Expr MINUSTK Expr
    | Expr STARTK Expr
    | Expr SLASHTK Expr
    | Factor
    | LPARENTK Expr RPARENTK
    ;