Open wenzong opened 11 years ago
I don't know anlr very much, but as I understand it, the example does result in an ast tree. But what you posted for JavaCC is not only the grammar but included additional parsing actions to collect the results of the parse process in a specific way, not a syntax tree. The simple grammar with all "code injections" removed is like:
void PlainSelect(): { } {
@wumpz Thanks for your advice and sorry for cause the misunderstanding to you. What you said is exactly what I mean by saying this:
To be honest, the mysql.g(ANTLR) is only a grammar file and it can't work directly. And the JSqlParser(JAVACC) hava many java code like:
Distinct distinct = new Distinct(); plainSelect.setDistinct(distinct);
Sometimes, you may spend many time for distinguish between grammar and java code
And I find that I give this issue a wrong name for what I really comparing is the JsqlParser 's jj file with mysql.g file. I will correct this wrong logic.
What I really mean is that newbies like me would be confused by the mix of grammar and parsing code.
And I think keep a copy of grammar file of JAVACC without "code injections" is a good idea. I will try it. :)
As mentioned in exist_tools.md, JSqlParser and ZQL are using JAVACC for parse sql statements, while mysql.g is also a tool for parse mysql sql statements(Using ANTLR).
After trying to add mysql supported feature into JSqlParser, I found that JSQLParser is not so clear for changing grammar tree.
Let's take a look at the two tools.
1. Mysql Select Syntax (dev doc)
2. JSQLParser
3. mysql.g
4. Style
The mysql.g grammar is more clear for mysql sql statement.
To be honest, the mysql.g(ANTLR) is only a grammar file and it can't work directly. And the JSqlParser(JAVACC) hava many java code like:
Sometimes, you may spend many time for distinguish between grammar code from java code.
Reg Expr is almost the same
JSQLParser grammar file
As @wumpz point out in the comment, the simple grammar in JAVACC is also very clear.
5. For Developer
JSQLParser is a ripe project
6. For My Goal
7. Other Things