[squeak-dev] Parser question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Parser question

Igor Stasenko
Just wonder, if following is correct expression:


| t |
1 + t := 5

--
not works in squeak (says 'nothing more expected'), but of course


| t |
1 + (t := 5)

works as expected.


--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Parser question

Randal L. Schwartz
>>>>> "Igor" == Igor Stasenko <[hidden email]> writes:

Igor> Just wonder, if following is correct expression:
Igor> | t |
Igor> 1 + t := 5

It seems to me that that should be wrong, because to me the assignment
operation is very low precedence. And the binary message send would therefore
be out of place. If it wasn't illegal already, I'd argue to make it illegal,
as it would lead to misleading code.


--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: Parser question

Paolo Bonzini-2
Randal L. Schwartz wrote:

>>>>>> "Igor" == Igor Stasenko <[hidden email]> writes:
>
> Igor> Just wonder, if following is correct expression:
> Igor> | t |
> Igor> 1 + t := 5
>
> It seems to me that that should be wrong, because to me the assignment
> operation is very low precedence. And the binary message send would therefore
> be out of place. If it wasn't illegal already, I'd argue to make it illegal,
> as it would lead to misleading code.

Yes, it should be wrong.  The grammar is:

   expression: keyword_expression cascaded_sends
      | variable ':=' expression

   keyword_expression: binary_expression
      | binary_expression keyword_send

   binary_expression: unary_expression
      | binary_expression binary_send

   unary_expression: primary_expression
      | unary_expression unary_send

   primary_expression: literal
      | variable
      | '(' expression ')'

   cascaded_sends: cascaded_sends ';' message_send
      | /* empty */

   message_send: keyword_send
      | binary_send
      | unary_send

   variable: IDENTIFIER
   unary_send: IDENTIFIER
   binary_send: BINOP unary_expression
   keyword_send: KEYWORD binary_expression
      | keyword_send KEYWORD binary_expression

So ':=' can only appear at toplevel or inside parentheses, and the above
is not valid.

Paolo