Bug 16710 - Parser: '=' appears to have lower precedence than '?'
Summary: Parser: '=' appears to have lower precedence than '?'
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Documentation (show other bugs)
Version: R-devel (trunk)
Hardware: Other Other
: P5 trivial
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-02-11 20:49 UTC by Kevin Ushey
Modified: 2016-02-11 20:49 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Ushey 2016-02-11 20:49:11 UTC
I was a little surprised to see this:

    > parse(text = "x ? y = z")[[1]]
    `?`(x, y) = z
    
    > parse(text = "x ? y <- z")[[1]]
    `?`(x, y <- z)

Note that `?` is binding more strongly than `=`. This seems related to https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14955, which discusses the fact that R uses a special reduction rule for `=`.

This is obviously an edge case, but it might be useful if the documentation in '?Syntax' were updated. For reference, I bumped into this when attempting to build my own R parser (as a learning exercise + for validation, diagnostics purposes)

Thanks,
Kevin

> sessionInfo()
R version 3.2.3 Patched (2016-02-03 r70081)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.3 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base