Understanding precedence of assignment and logical operator in Ruby
<p>I can't understand precedence of Ruby operators in a following example:</p>

<pre><code>x = 1 &amp;&amp; y = 2
</code></pre>

<p>Since <code>&amp;&amp;</code> has higher precedence than <code>=</code>, my understanding is that similarly to <code>+</code> and <code>*</code> operators:</p>

<pre><code>1 + 2 * 3 + 4
</code></pre>

<p>which is resolved as</p>

<pre><code>1 + (2 * 3) + 4
</code></pre>

<p>it should be equal to:</p>

<pre><code>x = (1 &amp;&amp; y) = 2
</code></pre>

<p>However, all Ruby sources (including internal syntax parser <code>Ripper</code>) parse this as</p>

<pre><code>x = (1 &amp;&amp; (y = 2))
</code></pre>

<p>Why?</p>

<hr>

<p><strong>EDIT [08.01.2016]</strong></p>

<p>Let's focus on a subexpression: <code>1 &amp;&amp; y = 2</code></p>

<p>According to precedence rules, we should try to parse it as:</p>

<pre><code>(1 &amp;&amp; y) = 2
</code></pre>

<p>which doesn't make sense because <code>=</code> requires a specific LHS (variable, constant, <code>[]</code> array item etc). But since <code>(1 &amp;&amp; y)</code> is a correct expression, how should the parser deal with it?</p>

<p>I've tried consulting with Ruby's <code>parse.y</code>, but it's so spaghetti-like that I can't understand specific rules for assignment. </p>