title: ANTLR4 parse tree simplification
body: <p>Is there any means to get ANTLR4 to automatically remove redundant nodes in generated parse trees?</p>
  
  <p>More specifically, I've been experimenting with a grammar for GLSL and you end up with long linear sequences of "expressions" in the parse tree due to the rule forwarding needed to give the automatic handling of operator precedence.</p>
  
  <p>Most of the generated tree nodes are simply "forward to the next level of precedence", so don't provide any useful syntactic information - you only really need the last expression node in each sequence (i.e. the point at which the rule forwarding stopped), or the point where it becomes an actual tree node with more than one child (i.e. an actual expression was encountered in the source) ...</p>
  
  <p>I was hoping there would be an easy way to kill off the dummy intermediate expression nodes - this type of structure must be common in any grammar with operator precedence.</p>
  
  <p>The basic structure of the grammar is a fairly direct clone taken from the Khronos specification for the language:</p>
  
  <p><a href="https://www.khronos.org/registry/gles/specs/3.1/es_spec_3.1.pdf" rel="nofollow">https://www.khronos.org/registry/gles/specs/3.1/es_spec_3.1.pdf</a></p>