You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Brian McCallister <mc...@forthillcompany.com> on 2004/05/03 02:07:40 UTC

Need Help with JDOQL Compiler/Interpreter

My knowledge of compilers/interpreters is nil. I'd really appreciate 
some help figuring out how to do JDOQL in a reasonable way!

There is BNF for it in the JDO spec, and it looks pretty basic -- but 
the naive hack I will wind up throwing together if I tackle it will be 
just that.

-Brian



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: Need Help with JDOQL Compiler/Interpreter

Posted by Brian McCallister <mc...@forthillcompany.com>.
No deadline -- but it's the biggest thing blocking JDO progress at the 
moment. That said, once JDOQL is in place, the next biggest thing 
becomes the biggest thing...

The BNF is published as part of the specification, so if the JDORI and 
spec grammars match, I think it would be safe to use the JDORI one. If 
it isn't, I'll happily type in the one from the spec if you can make it 
do something useful!

Thank You!

-Brian

On May 3, 2004, at 2:23 AM, Thomas Dudziak wrote:

> On Mon, 3 May 2004, Thomas Mahler wrote:
>
>> Hi Brian,
>>
>> The "real" way to deal with jdoql will be to use a parser-generator 
>> like
>> ANTLR. The parser Generator will be able to take an EBNF-like grammar
>> file and generate Java-programes implementing Lexer and Parser for the
>> language defined by the EBNF.
>
> Brian, how soon do you need the grammar ? I could put together an Antlr
> grammar at the end of the week.
>
>> In my mind the procdure for JDOQL will be quite similar as for ODMG 
>> OQL.
>> That is the parser should translate from JDOQL to PB query/criteria 
>> objects.
>> We are defining all parsing rules in a grammar file (oql.g). Antlr 
>> will
>> then generate the parser runtime classes from that grammar file.
>
> +1. In fact this makes it easy to test the grammar without even having 
> a
> database at hand. The unit tests simply input a JDOQL statement into 
> the
> parser and then check the resulting pb query.
>
>> As far as I remember there is an ANTLR grammar for JDOQL in the JDO 
>> RI.
>> This grammar could be a starting point for writing our own JDOQL ->
>> Query/Criteria grammar.
>
> Nope, AFAIK, its only a recursive decent BNF of JDOQL which can be 
> quite a
> hassle to convert into LL(k) (it surely was with the Java grammar).
>
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: Need Help with JDOQL Compiler/Interpreter

Posted by Thomas Dudziak <to...@first.gmd.de>.
On Mon, 3 May 2004, Jakob Braeuchi wrote:

> hi thomas,
> 
> looks like you are the antl guru i'm looking for.
> this is the post i made last october:
> 
> 
> hi all,
> 
> while playing with oql i realized that we do not support functions !
> 
>          OQLQuery query = odmg.newOQLQuery();
>          query.create("select anArticle from " +
>                  Article.class.getName() +
>                  " where upper(articleName) like \"A%\" ");
> 
> 
> the upper-function in the where clause causes antlr errors:
> 
> line 1: unexpected token: upper
> line 1: unexpected token: )
> 
> i tried to fix it by adding ( and ) to the valid characters for Identifier. but 
> breaks in and is_defined.
> 
> after some hours of digging in oql-ojb.g i have to admit that i'm stuck.
> so please antlr-gurus have a look at it.

The problem here is that the OQL grammar used by OJB is quite old and
also does not support arbitrary functions (upper is not even in the
current grammar from the ODMG website though).
Well, the short answer is that I could fix it (in this particular case you
would probably add 'upper' to the identifier list in conversionExpr) but
it would be specific for upper because the functions that are supported in
OQL are hardcoded within the grammar. This is of course bad ;-) A better
solution would be to have the grammer unaware of the supported
functions: it only spits out the identifier and the type (unary,
binary). The function lookup is done in a 2nd pass (e.g. an AST walker
that generates the query).
BTW, A couple of weeks ago I had a conversation with Phil Warrick on the
dev list about adding support of the newest OQL grammar (including several
other functions).

I can have a look at it when the JDOQL grammar is done (they'll be similar
in structure) but it probably means a major restructuring of the OQL 
parser (single pass -> two passes).

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: Need Help with JDOQL Compiler/Interpreter

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi thomas,

looks like you are the antl guru i'm looking for.
this is the post i made last october:


hi all,

while playing with oql i realized that we do not support functions !

         OQLQuery query = odmg.newOQLQuery();
         query.create("select anArticle from " +
                 Article.class.getName() +
                 " where upper(articleName) like \"A%\" ");


the upper-function in the where clause causes antlr errors:

line 1: unexpected token: upper
line 1: unexpected token: )

i tried to fix it by adding ( and ) to the valid characters for Identifier. but 
breaks in and is_defined.

after some hours of digging in oql-ojb.g i have to admit that i'm stuck.
so please antlr-gurus have a look at it.

jakob



Thomas Dudziak wrote:
> On Mon, 3 May 2004, Thomas Mahler wrote:
> 
> 
>>Hi Brian,
>>
>>The "real" way to deal with jdoql will be to use a parser-generator like 
>>ANTLR. The parser Generator will be able to take an EBNF-like grammar 
>>file and generate Java-programes implementing Lexer and Parser for the 
>>language defined by the EBNF.
> 
> 
> Brian, how soon do you need the grammar ? I could put together an Antlr
> grammar at the end of the week.
>  
> 
>>In my mind the procdure for JDOQL will be quite similar as for ODMG OQL.
>>That is the parser should translate from JDOQL to PB query/criteria objects.
>>We are defining all parsing rules in a grammar file (oql.g). Antlr will 
>>then generate the parser runtime classes from that grammar file.
> 
> 
> +1. In fact this makes it easy to test the grammar without even having a
> database at hand. The unit tests simply input a JDOQL statement into the
> parser and then check the resulting pb query.
> 
> 
>>As far as I remember there is an ANTLR grammar for JDOQL in the JDO RI.
>>This grammar could be a starting point for writing our own JDOQL -> 
>>Query/Criteria grammar.
> 
> 
> Nope, AFAIK, its only a recursive decent BNF of JDOQL which can be quite a
> hassle to convert into LL(k) (it surely was with the Java grammar).
> 
> Tom
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: Need Help with JDOQL Compiler/Interpreter

Posted by Thomas Dudziak <to...@first.gmd.de>.
On Mon, 3 May 2004, Thomas Mahler wrote:

> Hi Brian,
> 
> The "real" way to deal with jdoql will be to use a parser-generator like 
> ANTLR. The parser Generator will be able to take an EBNF-like grammar 
> file and generate Java-programes implementing Lexer and Parser for the 
> language defined by the EBNF.

Brian, how soon do you need the grammar ? I could put together an Antlr
grammar at the end of the week.
 
> In my mind the procdure for JDOQL will be quite similar as for ODMG OQL.
> That is the parser should translate from JDOQL to PB query/criteria objects.
> We are defining all parsing rules in a grammar file (oql.g). Antlr will 
> then generate the parser runtime classes from that grammar file.

+1. In fact this makes it easy to test the grammar without even having a
database at hand. The unit tests simply input a JDOQL statement into the
parser and then check the resulting pb query.

> As far as I remember there is an ANTLR grammar for JDOQL in the JDO RI.
> This grammar could be a starting point for writing our own JDOQL -> 
> Query/Criteria grammar.

Nope, AFAIK, its only a recursive decent BNF of JDOQL which can be quite a
hassle to convert into LL(k) (it surely was with the Java grammar).

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: Need Help with JDOQL Compiler/Interpreter

Posted by Thomas Mahler <th...@web.de>.
Hi Brian,

The "real" way to deal with jdoql will be to use a parser-generator like 
ANTLR. The parser Generator will be able to take an EBNF-like grammar 
file and generate Java-programes implementing Lexer and Parser for the 
language defined by the EBNF.

In my mind the procdure for JDOQL will be quite similar as for ODMG OQL.
That is the parser should translate from JDOQL to PB query/criteria objects.
We are defining all parsing rules in a grammar file (oql.g). Antlr will 
then generate the parser runtime classes from that grammar file.

As far as I remember there is an ANTLR grammar for JDOQL in the JDO RI.
This grammar could be a starting point for writing our own JDOQL -> 
Query/Criteria grammar.

cheers,
Thomas


Brian McCallister wrote:
> My knowledge of compilers/interpreters is nil. I'd really appreciate 
> some help figuring out how to do JDOQL in a reasonable way!
> 
> There is BNF for it in the JDO spec, and it looks pretty basic -- but 
> the naive hack I will wind up throwing together if I tackle it will be 
> just that.
> 
> -Brian
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org