[R] If statement generates two outputs
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Mar 24 10:28:15 CET 2009
Romain Francois wrote:
> This is probably due to that in the gram.y file :
>
> case ':':
> if (nextchar(':')) {
> if (nextchar(':')) {
> yylval = install(":::");
> return NS_GET_INT;
> }
> else {
> yylval = install("::");
> return NS_GET;
> }
> }
> if (nextchar('=')) {
> yylval = install(":=");
> return LEFT_ASSIGN;
> }
> yylval = install(":");
> return ':';
> which gives a meaning to ":=", so that parsing x := 2 makes sense.
>
> > parse( text = "x := 2" )
> expression(x := 2)
> attr(,"srcfile")
> <text>
thanks. so it seems to be intentionally parsable, though i wouldn't say
that this gives a meaning to ':=' -- the operator has a syntactic
category, but no semantics. the syntactic category does not imply any
semantics, as in
'<-' = function(a, b) NULL
1 <- a
# NULL
where '<-' is still parsed the original way (as a LEFT_ASSIGN, gram.y
again), but has now a completely different semantics.
it looks like a bug to me: ':=' is parsed on par with '<-' as a
LEFT_ASSIGN, but apparently is not backed by any function. it's a
zombie. (unless rvalues is used, that is.)
vQ
More information about the R-help
mailing list