|RE: Parsing some but not all of SQL firstname.lastname@example.org (Quinn Tyler Jackson) (2002-10-18)|
|From:||"Quinn Tyler Jackson" <email@example.com>|
|Date:||18 Oct 2002 23:08:16 -0400|
|Posted-Date:||18 Oct 2002 23:08:16 EDT|
> 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
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
Return to the
Search the comp.compilers archives again.