title: Handling ANTLR return values
body: <p>I have a grammar rule like this:</p>
  
  <pre><code>a returns [string expr] : (b | c) {$expr = "Build expression from b OR c here";}
  
  b returns [string expr] : 'B' {$expr = "From b";}
  
  c returns [string expr] : 'C' {$expr = "From c";}
  </code></pre>
  
  <p>I would like to replace </p>
  
  <pre><code>$expr = "Build expression from b OR c here"; 
  </code></pre>
  
  <p>with an instruction that puts in the $expr variable whatever was returned from b OR c. I know there is a solution to this by performing this assignment like this:</p>
  
  <pre><code>a returns [string expr] : b {$expr = $b.expr;} | c {$expr = $c.expr;}
  </code></pre>
  
  <p>but was wondering whether there is a much simpler way like naming the whole group with a variable and using that instead:</p>
  
  <pre><code>a returns [string expr] : group = (b | c) {$expr = $group.expr;}
  </code></pre>
  
  <p>I've tried this and it doesn't work in ANTLR, even though the group variable is used to get the value returned by "b".</p>