Cypher in BNF

577 views
Skip to first unread message

Athanasios Anastasiou

unread,
Jul 15, 2013, 7:31:27 AM7/15/13
to ne...@googlegroups.com
Hello All

The question is pretty much in the title, i am looking for the specification of Cypher in BNF.

A relevant post in this group (not from long ago) is: https://groups.google.com/forum/#!msg/neo4j/OQB7MdXEnvU/xUjLaVse57MJ

I am wondering if any progress has been made since then (?).


Trying to work out the syntax from "examples" would work for some simple cases but could lead to inaccurate representations and i would like to avoid it.

Taking a look at: https://github.com/neo4j/cypher-dsl/tree/master/src/main/java/org/neo4j/cypherdsl

I can somehow see the relevant terms i should define but i am not sure how is the parser put together from these concrete definitions.

My specific questions are as follows:

1) Is there anywhere any document that specifies Cypher's syntax in BNF?

2) Can anyone provide a short overview of the way that the parser is put together from the definitions found on the the cypher-dsl github project with the view
of using that description to put together the BNF specification?

Looking forward to hearing from you
Athanasios Anastasiou


Peter Neubauer

unread,
Jul 19, 2013, 9:27:36 AM7/19/13
to Neo4j User
Hi Athanasios,
there is no formal BNF (yet), but feel free to start one. Let's see how far we get!

/peter


Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Kids in Malmö this summer?        - http://www.kidscraft.se
Neo4j questions? Use GraphGist. - http://gist.neo4j.org



Athanasios Anastasiou


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Athanasios Anastasiou

unread,
Jul 23, 2013, 1:56:25 PM7/23/13
to ne...@googlegroups.com
Hello Peter

Thank you very much for your response... Before we do that, are we absolutely sure that there is no yacc-like file that matches patterns to actions in the current implementation? :)

All the best
Athanasios Anastasiou

Michael Hunger

unread,
Jul 23, 2013, 2:39:14 PM7/23/13
to ne...@googlegroups.com
It is a parser combinator / peg parser implemented in scala, see

Peter Neubauer

unread,
Jul 23, 2013, 4:46:11 PM7/23/13
to Neo4j User

I don't think so, the parser is implemented in scala. Feel free to look through the source.

/peter

(snt)-[:frm]->(phn)

Athanasios Anastasiou

unread,
Jul 24, 2013, 5:40:43 AM7/24/13
to ne...@googlegroups.com
Oh joy... :)

Alright, i will try to give it a stab then.

All the best
Athanasios Anastasiou

--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/sglGwRnqlg0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

Athanasios Anastasiou

unread,
Jul 25, 2013, 1:59:11 PM7/25/13
to ne...@googlegroups.com
Hello again

First version attached to this email along with its syntax diagram.

It's actually the syntax diagram that i want to generate and in fact not such a detailed version of it but a more concise one focusing primarily on the broad syntax rather than the very fine details. But in any case, having the BNF allows one to do various things, like syntax highlighting for editors, syntax diagrams, mapping queries from other languages and of course parsers themselves.

This is still work in progress, the BNF does not describe but very basic actual queries (a basic form of "create" and a basic form of "start match where return order by skip limit").

There are still some gray areas and a few minor issues have been verified using the neo4j-shell.

I will keep working on it...By the way, are there "test cases" for the parser that i could use to test if they would pass a validator based on this grammar?


All the best
Athanasios Anastasiou







On Friday, 19 July 2013 14:27:36 UTC+1, Peter Neubauer wrote:
todo_20130625_170648.txt
cypher_diagram.xhtml
README.MD
cypher.bnf

Michael Hunger

unread,
Jul 25, 2013, 7:56:29 PM7/25/13
to ne...@googlegroups.com
Hey,

really impressive, why don't you put it up in a github repository? Makes it easier to share and collaborate.
You can also put your generated .xhtml page on github pages of that repository to host them directly.

The parser tests live here for 1.9

and here for 2.0 (with MERGE, labels etc).
https://github.com/neo4j/neo4j/tree/2.0/community/cypher/src/test/scala/org/neo4j/cypher

Please send me (personally) your postal address and t-shirt size for a custom t-shirt.

HTH

Michael
<todo_20130625_170648.txt><cypher_diagram.xhtml><README.MD><cypher.bnf>

Athanasios Anastasiou

unread,
Jul 26, 2013, 12:37:26 PM7/26/13
to ne...@googlegroups.com
Hello Micheal


Thank you very much for your response.

I do have the current version on a bitbucket repository here: https://bitbucket.org/aanastasiou/cypher-bnf


All the best
Athanasios Anastasiou



Michael Hunger

unread,
Jul 26, 2013, 2:18:55 PM7/26/13
to ne...@googlegroups.com
Do you have an overview, which tools / editors could use that BNF to create syntax highlighting and completion?

Michael

Matt Luongo

unread,
Jul 26, 2013, 8:46:01 PM7/26/13
to ne...@googlegroups.com
This... is pretty cool. I was trying to piece the grammar together the other day, but you got quite a bit further than I did. If you get a little further I could use it to generate a parser for Python driver libraries...

Athanasios Anastasiou

unread,
Jul 28, 2013, 3:17:35 PM7/28/13
to ne...@googlegroups.com
Hello everyone

Michael, the BNF does not participate in the syntax highlighting per se, but knowing the definitions for each class, it is then easier to write the highlighting rules in whatever form each editor expects it to be.
Notepad++ has a very simple highlighting scheme (http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Languages) and "Sublime text editor" a more complex one that is also context sensitive (http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html), so you can have different highlighting rules depending on which block is being matched.

Matt, that sounds interesting, i have in mind to create a Cypher parser too once the BNF is done (most probably using pyparsing).

All the best
Athanasios Anastasiou


You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/sglGwRnqlg0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

[:Koen]

unread,
Nov 26, 2013, 2:12:55 AM11/26/13
to ne...@googlegroups.com
Hi, good work ! Any progress on this one to make it end-to-end complete and incorporate neo 2.x stuff ?

I.m.h.o. a good/robust/valid/thorough (verified by neo)  BNF / EBNF syntax notation of the cypher language will be of great value to exactly understand the syntax

It would be great if it became part of the neo ref cards

reg koen






Op zondag 28 juli 2013 21:17:35 UTC+2 schreef Athanasios Anastasiou:

Athanasios Anastasiou

unread,
Nov 26, 2013, 4:47:01 AM11/26/13
to ne...@googlegroups.com
Hello Koen

Thank you for your message, the repository with current work is available at:
https://bitbucket.org/aanastasiou/cypher-bnf

This includes the initial BNF layout plus a first syntax diagram which however can be optimised further.

Since then, i have started the transcription to pyparsing in an attempt to create an elementary parser (which is what i will need some time in the near future) but other than some simplistic examples with select as general tests, i have not progressed much. The end-goal would be to add a Cypher interface to Networkx to demonstrate the levels of parsing, making sense of the query parameters and then using these to query a Networkx graph.

All the best
Athanasios Anastasiou

Javier de la Rosa

unread,
Nov 26, 2013, 10:20:54 AM11/26/13
to ne...@googlegroups.com

On Tue, Nov 26, 2013 at 4:47 AM, Athanasios Anastasiou <athana...@gmail.com> wrote:
The end-goal would be to add a Cypher interface to Networkx

This would be awesome!


--
Javier de la Rosa
http://versae.es

flip101

unread,
Feb 23, 2014, 11:11:08 AM2/23/14
to ne...@googlegroups.com
Hi i also would be very interested in having a formal definition of the Cypher Query Language of the new 2.* versions of Neo4j. This then could be used to create a parser and a querybuilder. Does the current version of the BNF support labels? 

flip101

unread,
Feb 28, 2014, 2:08:32 PM2/28/14
to ne...@googlegroups.com
Hi it seems your BNF is EBNF?? Looking at a definition like this:
collection ::= "[" any_val (("," any_val)+)? "]"


Just to clear things up .. what notation technique are you using for the language definition? Maybe it's the ISO/IEC 14977 ??

It's important to know, because i'm writing a lexer/parser and i don't want to use the wrong grammar on this one. Thank you!

Op maandag 15 juli 2013 13:31:27 UTC+2 schreef Athanasios Anastasiou:

Athanasios Anastasiou

unread,
Feb 28, 2014, 2:47:50 PM2/28/14
to ne...@googlegroups.com

Hello there

Thank you for your message, the notation is W3C ebnf as understood by http://www.bottlecaps.de/rr/ui which at the moment is the primary "consumer" of the definition. Can i ask what are you building your parser with?

All the best
AA

flip101

unread,
Feb 28, 2014, 3:05:03 PM2/28/14
to ne...@googlegroups.com
Hi,

I'm using a compiler compiler (AKA parser generator) https://github.com/hoaproject/Compiler#llk-compiler-compiler since it uses it's own dedicated language i'm working on porting EBNF first. If you want to have a try with this kind of software take a look at these resources:

So i see you are using this EBNF format http://www.w3.org/TR/REC-xml/#sec-notation ok good to know.

Can you also please answer my previous question, with which i basically want to know how much % of cypher you have defined in EBNF (what things are supported and what things aren't) ??

Best regards

Op vrijdag 28 februari 2014 20:47:50 UTC+1 schreef Athanasios Anastasiou:

Athanasios Anastasiou

unread,
Mar 1, 2014, 10:52:30 AM3/1/14
to ne...@googlegroups.com

Hello

Thanks for the information. Can i ask what is your objective? What is it that you are trying to achieve with this?

As far as syntax is concerned i think that definitions are in place for almost all constructs of the language. However,some of the rules have been inferred from examples and so, there might exist a case that has not been taken into account.

However this is still only a small proportion of the work that would be required to build something that understands and executes cypher.

Extremely briefly, what you would have to do would be to look for the verbs of the language and implement them as functions with parameters. For example a START will create a simple set (of starting point nodes or rels) and a MATCH with its parameters (node-rel pattern) would filter this set.

The current set of definitions can help you parse these constructs but at the moment does not contain the interpertation part.

I have put a little bit more effort into this towards a pyparsing version which would be able to handle some of the interpertation as well using networkx but its too pre-alpha and i am still embarassed to add it to the repo :)

Hope this helps. If you find the defs useful and even expand them, please let me know and we'll get to add them, with appropriate acknowledgments of course, along with the rest.

All the best
Athanasios Anastasiou

flip101

unread,
Mar 15, 2014, 7:16:01 PM3/15/14
to ne...@googlegroups.com
Hi,

Thanks for your feedback again, I'm glad to hear you have reached much coverage.

I will leave the execution of Cypher to the Neo4j database. Not sure what other interpretation could be done, a parser would already construct an AST and there for interpret the Cypher Query. However it is interesting to construct Cypher query strings programmatically; that is start with programming constructs and from there convert them back into a Cypher query string.

I noticed your entry point goes like this:

query ::= create_node | (start match? where? (set|delete) return order_by? skip? limit?)

Where the start clause seems to be required. But since version 2.0 this is no longer required and you can start with a MATCH clause directly, see: http://docs.neo4j.org/chunked/milestone/query-match.html

In my opinion, for now the EBNF you provide can serve as a great inspiration, but is not ready to support the latest version of Neo4j.

I hope the neo4j team can help to construct an official language notation in EBNF for Cypher.

Op zaterdag 1 maart 2014 16:52:30 UTC+1 schreef Athanasios Anastasiou:
Reply all
Reply to author
Forward
0 new messages