jlemon
A fork of the
LEMON parser generator
that generates Java code and the associated SQL parser.
Files lemon.c
, lempar.c
are extracted from SQLite v3.18.0.
Usage
>
> cc -g -O2 -o jlemon lemon.c
>
> jlemon <filename>.y
>
> cpp -P <filename>.j > yyParser.java
For example:
cc -g -O2 -o jlemon lemon.c
./jlemon src/test/java/simple/parser.y
cpp -P src/test/java/simple/parser.j > src/test/java/simple/yyParser.java
mvn test
Or on Windows platform:
cl /O2 /Fejlemon.exe lemon.c
jlemon.exe src\test\java\simple\parser.y
cl /EP /C src\test\java\simple\parser.j > src\test\java\simple\yyParser.java
Generated Parser API
public class yyParser {
public yyParser(
ParseARG_PDECL
) {
}
public void ParseFinalize() {
}
public void Parse(
int yymajor,
ParseTOKENTYPE yyminor
){
}
}
Hack
As there is no union
in Java, yy%d
fields of YYMINORTYPE
have been replaced by yy%d()
getters and yy%d(%type value)
setters.
But when translating code (see translate_code
), the logic used to make the difference between a read access to a yy%d
field and a write access is fallible.
Maybe try a code manipulator (janino) ?
Or javolution Union ?
SQL Parser
SQLite lexer and SQLite parser have been ported from C to Java.
The parser generates an AST.
The parser is/will be used to fix DatabaseMetaData implementation.
- java.sql.DatabaseMetaData.getColumns
- java.sql.DatabaseMetaData.getPrimaryKeys
- java.sql.DatabaseMetaData.getBestRowIdentifier
- java.sql.DatabaseMetaData.getCrossReference
- java.sql.DatabaseMetaData.getImportedKeys
- java.sql.DatabaseMetaData.getExportedKeys
- java.sql.DatabaseMetaData.getIndexInfo
Lexer/Parser
- Keep track of position (line, column).
- Streamable (stop at the end of statement).
- Resumable (restart after the end of statement).
Test
SQL lexer and parser have been tested with the following scripts: