[antlr-interest] Interesting Problem
Hensley, Richard
richard.hensley at mckesson.com
Thu Sep 12 13:16:17 PDT 2002
I have an interesting parsing problem. I want dig certain context free
constructs out of a file, while ignoring all the other constructs in the
file. My specific case is that I have a file with a bunch of SQL in it,
but all I really care about are the create table statements. The create
table statements I'm concerned with can be parsed with the following
rules:
createTable
: "create" (ID)* "table" ID LPAREN columns RPAREN
;
columns
: column (COMMA column)*
;
column
: name datatype (ID)*
;
datatype
: ( "varchar" (size)*
| "varchar2" (size)*
| "number" (size)*
| "date"
| "integer"
| "long" ("raw")*
)
;
size
: LPAREN CARDINAL RPAREN
;
To solve this problem, I'm thinking of using token stream filters, but I
can't look ahead in a token stream filter so that I could recognize when
I'm in a create table statement.
My basic design would be to use a filter that turns on output of tokens
when in a create table statement, and the parser grammar would have a
semantic rule that would turn off token output when the create table
statement has been fully recognized.
Does anybody have any experience with such a thing?
Richard Hensley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20020912/0d7bfcf9/attachment.html
More information about the antlr-interest
mailing list