In ANTLR 4, you should relocate the embedded actions to a listener or visitor which you separately execute after the parsing phase is complete. You can use the Parser.getNumberOfSyntaxErrors
method prior to starting that phase to see if any parse errors occurred, and if so, stop processing at that point.
This covers all actions associated with the parser at once and results in a much cleaner overall code structure.