views:

1557

answers:

3

I'm currently working on a testing framework for regular expressions, and I need to be able to parse Java regular expressions into ASTs to be able to generate sample strings which match the given regex.

I looked at the implementation of java.util.regex.Pattern but the code looks quite unwieldy (the emphasis was on speed over readability I would imagine), so I decided to use ANTLR to write a regex parser from scratch.

I'm wondering if anyone knows of a ready ANTLR grammar for regex, before I start bashing one out myself.

+3  A: 

There's a similar question here:

http://stackoverflow.com/questions/265457/regex-grammar

The answers contain links to assorted grammars, none of them ANTLR ones. I suspect that if you translated the BNF one to ANTLR, you'd be plagued by left-recursion headaches but it's worth a try, you might get lucky.

izb
To deal with left recursion, see http://javadude.com/articles/lalrtoll.html - also, I believe some of the ANTLR 3 tools can help eliminate left recursion.
Scott Stanchfield
Unfortunately the ones provided in the question are not really suited to my needs. I decided to implement the ANTLR grammar from scratch and its looking good. Still, the examples were a good starting point so thanks.
Il-Bhima
A: 

hello i want the regular expression of java lexical analyzer thanks

iman
A: 

Does anybody know where to find tutorial for ANTLR grammar?

Robin
Off topic, down voted.
EJP