RE: Parsing some but not all of SQL

"Quinn Tyler Jackson" <>
18 Oct 2002 23:08:16 -0400

          From comp.compilers

Related articles
RE: Parsing some but not all of SQL (Quinn Tyler Jackson) (2002-10-18)
| List of all articles for this month |

From: "Quinn Tyler Jackson" <>
Newsgroups: comp.compilers
Date: 18 Oct 2002 23:08:16 -0400
Organization: Compilers Central
Keywords: parse, SQL
Posted-Date: 18 Oct 2002 23:08:16 EDT
In-reply-to: 02-09-152

> I am using yacc&lex to analysis a SQL batch. I only want to find
> out the SELECT statements in the batch and make some transformation
> to them. Other statements will not be changed.

> Must I write a full syntax of SQL, or are there some other simple
> ways?

Well, it's not lex&yacc, but ...

Meta-S grammars have two "modes".

In "accepting" mode, grammars behave as expected. (They must accept
the entire input, and thus, grammars must account for all

In "scanning" mode, grammars behave like a turbocharged version of
grep. That is, anything that doesn't match is simply ignored. You can
repeatedly call the MatchNext member function, and jump to the next

If you are ever (in future) interested in more than just "SELECT",
say, more than two different structures, you would simply specify a
disjunction in your goal production:

S ::= select_statement | if_statement;

As long as the first lexeme of your targeted statement types were
terminals, scanning $-grammars behave in an O(n) fashion.

(Insert product author disclosure here.)
Quinn Tyler Jackson

Post a followup to this message

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