Question

I'd like to exclude certain tokens from the parse-tree in antlr4.

Say I have this definition:

assignStatement: assignable EQ expression EOS;

EQ: '=';
EOS: ';';

The resulting parse-tree contains the assignable, EQ, expression and EOS as children of assignStatement. Is there any way to get rid of EQ and EOS here, since I only need them during parse-time for matching purposes?

Was it helpful?

Solution

ANTLR 4 does not omit matched terminals from the parse tree. While your application does not require access to those tokens, our experience has been that new applications using a previously written grammar frequently require access to elements that earlier applications did not. By including all elements in the parse tree, we are accounting for this case in advance to improve the long-term maintainability of applications using ANTLR 4.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top