[antlr-interest] Interesting Problem
mzukowski at yci.com
mzukowski at yci.com
Thu Sep 12 13:20:46 PDT 2002
Check out a similar problem/solution at
http://www.codetransform.com/filterexample.html
I use a parser to find particular constructs and pass the rest on.
Or, you might be able to do it all in the lexer with a filter rule. See the
article about using antlr like sed on antlr.org.
Monty
-----Original Message-----
From: Hensley, Richard [mailto:richard.hensley at mckesson.com]
Sent: Thursday, September 12, 2002 1:16 PM
To: 'antlr-interest at yahoogroups.com'
Subject: [antlr-interest] Interesting Problem
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
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list