title: ANTLR4 Visitor subtree check
body: <p>I have an Antlr4 question.  Given the grammar excerpt below. What is the correct approach to testing for the existence of the optional <code>actualParameters</code> subtree within a visitor?  </p>
  
  <p>I have tried the getChildCount method of the procedureCallStatement context. I've also tested for a null actualParameters parameter on the context.  </p>
  
  <p>I do not want to visit the actualParameters subtree if it does not exist.  Doing so causes an exception.</p>
  
  <p>Thank you!</p>
  
  <p>Kelvin Johnson</p>
  
  <pre><code>program : statement (';' statement)* ';'?;
  
  statement : CALLPREFIX('(' actualParameters? ')')?  #procedureCallStatement;
  
  actualParameters : expressionStatement (';' expressionStatement)* ;
  
  expressionStatement : '(' expressionStatement ')'  #parensExpression
  | IDENT'[' expressionStatement ']' #subscript
  ...
  </code></pre>