Re: SQL Parsing (Edward G. Nilges)
6 Oct 2001 15:55:12 -0400

          From comp.compilers

Related articles
SQL parsing (2000-06-30)
SQL Parsing (2001-09-30)
Re: SQL Parsing (2001-10-06)
Re: SQL Parsing (2001-10-20)
Re: Simple query parser (2002-04-06)
| List of all articles for this month |

From: (Edward G. Nilges)
Newsgroups: comp.compilers
Date: 6 Oct 2001 15:55:12 -0400
References: 01-09-132
Keywords: SQL, parse, comment
Posted-Date: 06 Oct 2001 15:55:12 EDT (isterin) wrote...
> I am trying to develop an SQL parser, which creates a multidimensional
> data structure based on SQL. My question is regarding the
> parenthesised precedence. I am having problems doing this from
> scratch, though have a few things in mind. I am doing this in Perl,
> if it matters, though the concept is what I really need.

I developed the SQL parser for a data base company using recursive
descent. Unlike lex and yacc this proceeds top down. It uses
recursion heavily.

The algorithm is fully described in Aho, Sethi and Ullman's "Dragon
Book" COMPILERS (Addison Wesley, 1985) and many more modern books. It
involves making or stealing the formal BNF of the language and then
writing procedures that track the BNF. Things to watch out for
include right association of asymmetric operations which require a
clumsy but workable fix, and deficiencies in the BNF which exist
because it makes the BNF cleared to humans, but subtly ambiguous.

I've used lex and yacc but am discontent with the ugly code they
generate and the fact that mostly they generate C. Since I am
currently working in VB.Net this is a drawback. It IS possible to
write production quality compilers in VB.Net, since you generate
Common Interface Language which is optimizable on either side of the
generation, and since the VB.Net runtime IS Common Interface Language,
meaning no performance penality for using VB.Net. However at this
writing compiler builder tools do not exist for VB.Net.

At the DB company I walked in with Open Source I'd developed to parse
not SQL but VB. I generalized the code by making it table-driven and
able to parse a class of languages of the general type of both Visual
Basic and SQL.

> [SQL isn't that hard to parse using tools like yacc. There's a parser I
> wrote for an older version of SQL in the archives that you can start with.
> -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.