Contents    Page-10    Prev    Next    Page+10    Index   

Semantics Influences Parsing

Example: Operator Precedence:

A + B * C
means: A + (B * C)
not: (A + B) * C

Possible solutions:

  1. Unambiguous operator precedence grammar.
    Large, ugly grammar and parser.
    In Pascal, the grammar is not large, but lack of precedence forces the programmer to parenthesize:
    
           if ( x > y && y > z ) ...
    
           if x > y and y > z then ...
    
    The Pascal version shown above generates an error; it must be written as:
    
           if (x > y) and (y > z) then ...
    

  2. Ambiguous grammar; precedence guides parser.
    Short, simple, clean grammar and parser.