Cypher AST

Hi all! I was wondering: Is there a way to produce a AST from a Cypher query ? Like a Cypher Parser or something like that?

Hello @daniel_amigos !

The best resources for a Cypher language parser are available over on .

You'll find grammar definitions and such there.

There's a reference implementation in Java that you can find here:


Not strictly an AST ( more of a parse tree) but when you combine it with the symbol tree, you get close.

Start with this Cypher.g4.txt (22.6 KB)
The ANTLR site ( and the two books on it) gives pretty good descriptions on generating the files. Unless you plan to do a lot, the python generated is pretty easy to use, the java and typescript are good.

Once you have a parser/lexer, you will need to write a visitor. Easy enough. OR if your needs are simpler, look at generating a .dot file (Graphviz) which is a very simple parse tree/ast.

We incorporated it into our product easily. Its not a wildly complex language and it does parse well.

1 Like