ANTLR: Get token name?
问题 I've got a grammar rule, OR : '|'; But when I print the AST using, public static void Preorder(ITree tree, int depth) { if (tree == null) { return; } for (int i = 0; i < depth; i++) { Console.Write(" "); } Console.WriteLine(tree); for(int i=0; i<tree.ChildCount; ++i) Preorder(tree.GetChild(i), depth + 1); } (Thanks Bart) it displays the actual | character. Is there a way I can get it to say "OR" instead? 回答1: robert inspired this answer. if (ExpressionParser.tokenNames[tree.Type] == tree.Text