On `lvalue` definition

I am going through the chapel grammar rules and I noticed

lvalue-expression:
  variable-expression
  member-access-expression
  call-expression
  parenthesized-expression

however the last is defined as

parenthesized-expression:
  ( expression )

which would mean that any expression can be used as lvalue as long as wrapped into parenthesis?! (at least syntactically, of course would fail semantically at latest). Is this really the case?

Hi Luca,

While it is indeed the case given these productions, the syntax used by the Chapel compiler in chpl.ypp is more complex than the language specification presents. Regardless, the Chapel parser indeed accepts a lot of programs that are incorrect semantically. This could be because of a non-lvalue expression where an lvalue expression is required, because an identifier is used inappropriately, a call is not resolved, and so on. In these cases later compiler passes reject the program.

How does this answer your question? Or maybe you are suggesting that we replace parenthesized-expression with parenthesized-lvalue-expression in this case? Maybe, however I'd argue that this does not matter. That's because the other three categories -- variable, member, call -- can easily be non-lvalue and we cannot restrict them to lvalues syntactically.

Vass

1 Like

Thanks Vass, that makes a lot of sense. I guess I was mainly trying to understand if it was simply a shortcut in the language specifications or there was a deeper semantics for allowing it.

I agree there's no need to change the documentation, the language specification section is already very clear and systematic. It makes sense to prefer clearance of exposure over pedantic rigour for the composition rules there