3

For our CMIS server side implementation, I am looking to build a parser that will parse query statements provided as input to the query method. CMIS defines a BNF grammar for the query statements. I was wondering what would be the best way to generate this BNF parser?

Our implementation is in C#. CMIS queries are based on SQL syntax plus some predicates defined by CMIS.

Mandar
  • 303
  • 4
  • 18
  • There is some info on parsing in C# here http://stackoverflow.com/questions/7377344/how-do-i-write-a-parser-in-c – Lee Meador Jan 22 '13 at 15:40
  • SQL in general is a pretty complicated langauge. The most straightforward answer is, "get a parser generator with an existing grammar for SQL" so you don't have to replicate that. But, morst parser generators build, well, parsers. However, parsing is generally a means to an end, not a goal itself. A more interesting question is what do intend to do after parsing? That may change the answer a lot. – Ira Baxter Jan 22 '13 at 17:44
  • @IraBaxter - The grammar I will have to use is defined by CMIS which is based on SQL plus some predicate defined by CMIS standard. So the queries will be like "SELECT * FROM cmis:document WHERE IN_FOLDER(10230)". Once the parser validates and classifies a query I can then call appropriate code according to predicates within the query. – Mandar Jan 23 '13 at 11:44
  • "Call appropriate code"... that doesn't answer the question about what you want to acheive. What do the appropriate code *do*? Does it execute the entire CMIS SQL query? What I'm trying to find out is how much analysis of the SQL query you have do on top of parsing. – Ira Baxter Jan 23 '13 at 14:19
  • @IraBaxter - As I said, CMIS SQL queries are different than plain SQL. So I can't really execute those as is. The table names, column names too would be different than our internal tables. So we need to translate that as well. A query like "SELECT cmis:name FROM cmis:document" would need such translation. For another query like "SELECT * FROM cmis:document WHERE In_TREE(folder_id)", we have to write code to return all documents in the tree of specified folder. Also a query like "SELECT SCORE() FROM cmis:document WHERE CONTAINS('some text')" will need us to use our full-text search capability. – Mandar Jan 23 '13 at 15:04

1 Answers1

2

Apache Chemistry OpenCMIS uses Antlr on the server side to parse, validate and interpret the cmisQL syntax. You can try to reuse Antlr grammar defined in the Apache Chemistry OpenCMIS implementation for generating your own C# parser with antlr3

OpenCMIS grammar files are available here (under the Apache Licence)

Julien Boulay
  • 1,164
  • 7
  • 15
  • A more recent set of C# target documentation for ANTLR 3 is available here: http://www.antlr.org/wiki/display/ANTLR3/Antlr3CSharpReleases – Sam Harwell Mar 05 '13 at 20:04