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


Groups > comp.compilers > #1517

Re: Grammar with low-precedence postfix operator?

Path csiph.com!usenet.pasdenom.info!news.lightlink.com!news.iecc.com!.POSTED!nerds-end
From Robert Jacobson <rljacobson@gmail.com>
Newsgroups comp.compilers
Subject Re: Grammar with low-precedence postfix operator?
Date Sat, 7 Feb 2015 10:30:43 -0800 (PST)
Organization Compilers Central
Lines 29
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <15-02-015@comp.compilers> (permalink)
References <15-02-006@comp.compilers> <15-02-010@comp.compilers>
NNTP-Posting-Host news.iecc.com
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 8bit
X-Trace miucha.iecc.com 1423385609 66990 2001:470:1f07:1126:0:676f:7373:6970 (8 Feb 2015 08:53:29 GMT)
X-Complaints-To abuse@iecc.com
NNTP-Posting-Date Sun, 8 Feb 2015 08:53:29 +0000 (UTC)
Injection-Date Sat, 07 Feb 2015 18:30:43 +0000
Keywords parse, design
Posted-Date 08 Feb 2015 03:53:29 EST
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:1517

Show key headers only | View raw


Thanks for the response. I'll have to digest this for a bit.

On Friday, 6 February 2015 22:12:10 UTC-5, Kaz Kylheku  wrote:
> On 2015-02-05, Robert Jacobson <rljacobson@gmail.com> wrote:
> > I'm trying to write an ANTLR4 grammar for a language with a low precedence
> > postfix operator (Wolfram Language with '&', but I use a simple toy grammar
> > below). I'm struggling with finding the right pattern to express this > > language.
>
> I suspect this is not nicely solvable by LALR type tools. Only with hacks.

But if I abandon implicit multiplication, collapse the grammar to a single
rule, and let ANTLR handle operator precedence, ANTLR produces a parser that
works. (I haven't made an attempt at a yacc grammar.) Perhaps this is because
ANTLR produces ALL(*) parsers.


> If you want 2+2++^3 to mean (2+2)++^3, that means that you need
> a special low-precedence versions of ^ (and other operators) for that
> case, so the ++ expression can be a constituent of something.
>
> Try something along these lines. This Yacc grammar only gives me one
> shift-reduce conflicts, on account of the empty production rule for
> pp_factor_continue.  I didn't test it; I only skimmed through the state
> transitions in y.output:


I'll experiment with this, but this strategy strikes me as impractical for
large grammars because you'd need to duplicate a significant portion of the
grammar for the low-precedence versions of operators that can follow ++, yes?

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


Thread

Grammar with low-precedence postfix operator? Robert Jacobson <rljacobson@gmail.com> - 2015-02-05 13:27 -0500
  Re: Grammar with low-precedence postfix operator? Kaz Kylheku <kaz@kylheku.com> - 2015-02-05 21:10 +0000
    Re: Grammar with low-precedence postfix operator? Robert Jacobson <rljacobson@gmail.com> - 2015-02-07 10:30 -0800
  Re: Grammar with low-precedence postfix operator? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-02-07 11:27 +0000
    Re: Grammar with low-precedence postfix operator? jgk@panix.com (Joe keane) - 2015-02-10 21:03 +0000
      Re: Grammar with low-precedence postfix operator? Kaz Kylheku <kaz@kylheku.com> - 2015-02-11 02:19 +0000
  Re: Grammar with low-precedence postfix operator? Stefan Monnier <monnier@iro.umontreal.ca> - 2015-02-08 12:34 -0500
    Re: Grammar with low-precedence postfix operator? Kaz Kylheku <kaz@kylheku.com> - 2015-02-09 01:24 +0000
      Re: Grammar with low-precedence postfix operator? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2015-02-09 08:05 +0100
  Re: Grammar with low-precedence postfix operator? Robert Jacobson <rljacobson@gmail.com> - 2015-02-21 12:55 -0800

csiph-web