'ANTLR4 parse tree doesn't contain rule names

ANTLR4 doesn't show rule names in parse tree.

For example, 1 + 2 is printed as:

Simple expression's tree

Code in main:

    std::string test = "1 + 2";
    ANTLRInputStream input(test);
    GrammarLexer lexer(&input);
    CommonTokenStream tokens(&lexer);
    GrammarParser parser(&tokens);

    auto *tree = parser.expression();

    std::cout << tree->toStringTree(true) << "\n";


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source