From konr@d@rudo|ph @end|ng |rom gm@||@com  Fri Jan 10 11:59:16 2020
From: konr@d@rudo|ph @end|ng |rom gm@||@com (Konrad Rudolph)
Date: Fri, 10 Jan 2020 10:59:16 +0000
Subject: [Rd] Operator precedence of =, <- and ?
Message-ID: <CAM2gKPZ6PjQBqFGsmbsUXMRtZWFBRzAf=w2DQUFOhNBwMewieg@mail.gmail.com>

The documentation (help("Syntax")) gives the operator precedence of the
assignment operators and help, from highest to lowest, as:

       ?<- <<-?           assignment (right to left)
       ?=?                assignment (right to left)
       ???                help (unary and binary)

If I understand correctly this implies that `a = b ? c` and `a <- b ? c`
should parse identically. Or, if using the unary version, `?a = b` and `?a
<- b` should parse identically.

However, as noted by Antoine Fabri on Stack Overflow [1], they have
different parses (on R 3.5.3 and 3.6.1, at least), which puts the
precedence of `?` *between* that of `<-` and `=`. In fact, src/main/gram.y
[2] appears to show the same precedence table as the documentation;
presumably the parser at some point rewrites the parse tree manually.

At any rate, should this be fixed in the documentation? Or is the
documentation ?correct?, and there?s a bug in the parser (in some versions
of R)?

[1] <
https://stackoverflow.com/questions/1741820/51564252#comment105506343_51564252
>
[2] <
https://github.com/wch/r-source/blob/386c3a93cbcaf95017fa6ae52453530fb95149f4/src/main/gram.y#L384-L390
>

--
Konrad Rudolph

	[[alternative HTML version deleted]]



[Rd] Operator precedence of =, <- and ?
Konrad Rudolph