[antlr-interest] case-insensitive parsing

Nick Vlassopoulos nvlassopoulos at gmail.com
Thu Apr 23 05:22:07 PDT 2009


Hi Bob,

I am in no case an antlr or grammar expert, but it appears to me that what
you want is context sensitive parsing.
http://www.antlr.org/doc/glossary.html#Context-sensitive has some notes on
how to achieve this!

Hope this helps,

Nikos

On Thu, Apr 23, 2009 at 12:11 PM, Bob Sole <bob.sole at googlemail.com> wrote:

> I'm trying to write a parser for PL/SQL package header files but I'm
> banging my head against the wall with a basic problem to do with
> case-insensitive parsing. I'm using Jim Idle's NoCaseFileStream to convert
> tokens into upper case, but I'm finding that the parser gets confused when
> it comes across language keywords that are embedded within comments. Here's
> some example input which has the OR keyword embedded within the package
> comment. The "create or replace package" statement is deliberately messed up
> - the parser handles this correctly, but it stumbles against the first 'or'
> on line 2:
>
> /**
> blah blah or blah
> */
> create Or rePlace PACKAGE
> test IS
>
> Here's the grammar:
>
> grammar Test;
>
> input: statement+ ;
>
> statement: pkgComment | pkgStmt ;
>
> pkgComment: '/**' description '*/' ;
>
> pkgStmt: 'CREATE' ('OR' 'REPLACE') 'PACKAGE' ID ('AS' | 'IS')
>                {System.out.println("found package: "+$ID.text); }
>         ;
>
> descrption: (ID {System.out.println(" description: ID="+$ID.text);})+ ;
>
> ID: Letter (Letter | Digit)* ;
>
> NUMBER: Digit Digit* ('.' Digit*)? ;
>
> fragment
> Digit: '0'..'9' ;
>
> fragment
> Letter: 'a'..'z' | 'A'..'Z' | '_' ;
>
> NL: ('\r'? '\n') { skip();} ;
> WS: (' '| '\t') {skip();} ;
>
> EVERYTHING_ELSE: . ;
>
>
> I get the following output which shows that the pkgStmt parsing is ok, but
> the pkgComment isn't working:
>
> line 11:2 mismatched character '-' expecting '*'
> description: ID=blah
> description: ID=blah
> line 2:10 mismatched input 'or' expecting '*/'
> found package: test
>
> I'm slowly working my way through the book, and I've looked through the
> wiki FAQs and postings here but haven't found anything that'll help me (that
> I can understand, at least!) - any suggestions would be most appreciated!
>
> Thanks in advance!
> Bob.
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090423/ff9cd4dc/attachment.html 


More information about the antlr-interest mailing list