Bill Allombert on Fri, 25 Mar 2022 10:42:51 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Parser’s bug? Parentheses in an "s"-type argument


On Thu, Mar 24, 2022 at 08:20:58PM -0700, Ilya Zakharevich wrote:
> I’m not sure it is a bug (do not know whether the syntax is
> documented anywhere), but this definitely makes it harder to write a
> readable code.
> 
> (19:23) gp > my(a=0,b=1);print(a"\t"(a+=b))
>   ***   at top-level: my(a=0,b=1);print(a"\t"(a+=b))
>   ***                                    ^-----------
>   ***   not a function in function call

This is not a bug, this is an ambiguous case.
You should just add commas:
my(a=0,b=1);print(a,"\t",(a+=b))

Omitting the commas is only supported for backward compatibility
and is discouraged.

What happen here is that 
print(a"\t"a+=b) is parsed as 
print(a<ERROR>"\t"<ERROR>a+=b)
and the <ERROR> token are replaced by ','
but
print(a"\t"(a+=b)) is parsed as 
print(a<ERROR>"\t"(a+=b))
because for the parser point of view, "\t"(a+=b) is a function call,
not a syntax error.

Cheers,
Bill.