[antlr-interest] Re: Interesting Problem

lgcraymer lgc at mail1.jpl.nasa.gov
Thu Sep 12 13:52:40 PDT 2002


A brute force method would be to change your top-level definition to

     (    "create" ((table)=> table)?
          | ~"create"
     )* EOF

with table being your createTable rule minus the "create" and all 
actions confined to table and the rules that it invokes.

Adding a token stream filter would then improve performance--the 
action in the ~"create" alternative would be to toggle nextToken to 
skip tokens until "create" is encountered--but not functionality.


--- In antlr-interest at y..., mzukowski at y... wrote:
> 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 m...]
> Sent: Thursday, September 12, 2002 1:16 PM
> To: 'antlr-interest at y...'
> Subject: [antlr-interest] Interesting Problem
> I have an interesting parsing problem. I want dig certain context 
> constructs out of a file, while ignoring all the other constructs in 
> 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 
> statements I'm concerned with can be parsed with the following 
> 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 
>     ; 
> 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 
> 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