Related articles |
---|
RE: Parsing some but not all of SQL qjackson@shaw.ca (Quinn Tyler Jackson) (2002-10-18) |
From: | "Quinn Tyler Jackson" <qjackson@shaw.ca> |
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
possibilities.)
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
match.
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
http://members.shaw.ca/qjackson/
http://members.shaw.ca/jacksonsolutions/
Return to the
comp.compilers page.
Search the
comp.compilers archives again.