Re: precedences vs. hierarchy

Kaz Kylheku <>
Tue, 7 Jun 2016 15:35:56 +0000 (UTC)

          From comp.compilers

Related articles
precedences vs. hierarchy (Andreas Schramm) (2016-06-06)
Re: precedences vs. hierarchy (Dmitry A. Kazakov) (2016-06-06)
Re: precedences vs. hierarchy (George Neuner) (2016-06-06)
Re: precedences vs. hierarchy (2016-06-06)
precedences vs. hierarchy (SLK Mail) (2016-06-07)
Re: precedences vs. hierarchy (Kaz Kylheku) (2016-06-07)
Re: precedences vs. hierarchy (Dmitry A. Kazakov) (2016-06-07)
Re: precedences vs. hierarchy (2016-06-08)
| List of all articles for this month |

From: Kaz Kylheku <>
Newsgroups: comp.compilers
Date: Tue, 7 Jun 2016 15:35:56 +0000 (UTC)
Organization: NNTP Server
References: 16-06-001 16-06-004
Injection-Info:; posting-host=""; logging-data="54517"; mail-complaints-to=""
Keywords: parse, comment
Posted-Date: 07 Jun 2016 12:59:09 EDT

On 2016-06-06, Dmitry A. Kazakov <> wrote:
> On 06/06/2016 09:08, Andreas Schramm wrote:
>> for specifying the syntax of operator expressions
>> with multiple levels of precedences,
>> there are essentially two approaches:
>> (i) by precedence and associativity declarations, and
>> (ii) by a hierarchy of non-terminals.
> (iii) By only precedence, which I prefer. Associativity is not needed if
> operator precedence is split into the left and right ones. That allows
> to express any associativity, unary operators included.


You need the concept of associativity to tell whether
A + B + C is (A + B) + C or A + (B + C).

The + here is the same operator and so it precedence is equal to itself.
Moreover, it may be on the same precedence level as other operators such
as the binary -.

In table shift-reduce parsers (Yacc, and such), associativity rules
resolve conflicts.

When the generated parser has seen the input A + B, and the lookahead
symbol is +, it needs to know whether to shift the + (right
associativity), or to reduce the A + B (left associativity).

Unary and postfix operators do not require associativity because
they are not ambiguous. op op op expr where op is a unary op,
this can only mean op ( op ( op expr )), by the grammar alone.

Ambiguity arises if there are both postfix and prefix operators
hanging on the same expression; that is resolved by precedence.
[If you can specify the left and right precedence for an operator
separately, that gives you the associativity. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.