Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #1714

Re: precedences vs. hierarchy

Path csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From Kaz Kylheku <545-066-4921@kylheku.com>
Newsgroups comp.compilers
Subject Re: precedences vs. hierarchy
Date Tue, 7 Jun 2016 15:35:56 +0000 (UTC)
Organization Aioe.org NNTP Server
Lines 37
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <16-06-008@comp.compilers> (permalink)
References <16-06-001@comp.compilers> <16-06-004@comp.compilers>
Injection-Info miucha.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="54517"; mail-complaints-to="abuse@iecc.com"
Keywords parse, comment
Posted-Date 07 Jun 2016 12:59:09 EDT
X-submission-address compilers@iecc.com
X-moderator-address compilers-request@iecc.com
X-FAQ-and-archives http://compilers.iecc.com
Xref csiph.com comp.compilers:1714

Show key headers only | View raw


On 2016-06-06, Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> 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.

What?

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]

Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

precedences vs. hierarchy Andreas Schramm <bassobajo@gmail.com> - 2016-06-06 09:08 +0200
  Re: precedences vs. hierarchy "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2016-06-06 17:08 +0200
    Re: precedences vs. hierarchy Kaz Kylheku <545-066-4921@kylheku.com> - 2016-06-07 15:35 +0000
      Re: precedences vs. hierarchy "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2016-06-07 22:53 +0200
      Re: precedences vs. hierarchy anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-06-08 09:48 +0000
  Re: precedences vs. hierarchy George Neuner <gneuner2@comcast.net> - 2016-06-06 12:35 -0400
  Re: precedences vs. hierarchy federation2005@netzero.com - 2016-06-06 14:01 -0700
    Example: The Full Syntax Of Prolog (Re: precedences vs. hierarchy) rockbrentwood@gmail.com - 2016-08-24 15:45 -0700

csiph-web