Q:

How to develop a AST(Abstract Syntax Tree) for XPath?

Could anyone teach me how to develop an AST(Abstract Syntax Tree) for XPath?
Totally confused.
Thanks!

A:

Using ANTLR is a fine way to get started doing this.
BUT: build something simple, like an expression parser, first.  This will make sure you understand the basics.  You'll likely find dozens of examples of this for ANTLR, I suspect even here on stack overflow.  
After you get an expression grammar and an AST for it, then consider XPath.  You'll discover this is a LOT more complicated, mostly because the definition of XPath was created by one committee, building on the giant XML construction of another committee.  So your problem will be a little bit knowing how to build ASTs with parsers, and a LOT with reading all the gook that those two committees wrote to define XPath.

