2

I would like to show all tokens and roles that was reached during the parser with Antlr 4, excluding all extra rules on the grammar.

    ANTLRInputStream input = new ANTLRInputStream(is);
    CerlLexer lexer = new CerlLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    CerlParser parser = new CerlParser(tokens);
    ParseTree tree = parser.program();
    System.out.println(tree.toStringTree(parser));

Can I do that using Antlr 4 ?

fvarj
  • 205
  • 1
  • 3
  • 9

1 Answers1

2

Set trace to true by calling parser method setTrace()

parser.setTrace(true);

It will not print the rules that are not reached.

JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
yoshi
  • 1,070
  • 9
  • 16