11

I am interested in parsing regexes (not to be confused with using regexes for parsing). Is there a BNF for Java 1.6 regexes (or other languages?)

[NOTE: There is a similar older question which did not lead to an answer for Java.]

EDIT To explain why I need to do this. We are implementing a shallow parser for Natural language processing which first identifies and tags tokens. These are then further processed with a regex. I need to know what groups have been captured by the regex (the automaton only captures the last of each bracket) and I also want to annotate the regex with comments.

Community
  • 1
  • 1
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217

3 Answers3

6

Here they point to attempts at describing Perl's regexes in BNF:

http://www.cs.sfu.ca/~cameron/Teaching/384/99-3/regexp-plg.html

http://www.faqts.com/knowledge_base/view.phtml/aid/25718/fid/200

Community
  • 1
  • 1
Vinko Vrsalovic
  • 330,807
  • 53
  • 334
  • 373
  • http://www.faqts.com/knowledge%5Fbase/view.phtml/aid/25718/fid/200 doesn't work for me – Makach Sep 16 '09 at 21:18
  • @Makach: Replace `%5F` with `_`. SO seems to replace that in URLs. – Gumbo Sep 16 '09 at 21:20
  • The faqts link appears to be dead. The sfu.ca link provides neither epsilon nor optional, and as such can't specify all regular languages let along something as complex as a perl regex. – Recurse Mar 19 '13 at 04:58
2

I don't see one specifically for java 1.6; but here's a start that maybe you can build a complete BNF from:

http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/wd/regexp.html#RegularExpressionBNF

...using the java 1.6 documentation for Pattern:

http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html

RMorrisey
  • 7,637
  • 9
  • 53
  • 71
  • Also you should be aware, if you weren't already, that the JDK has support for regular expressions (see the Pattern class linked in this post) - be sure you aren't reinventing the wheel. – RMorrisey Sep 16 '09 at 21:09
0

There does not seem to be an explicit regex according to SO replies.

peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217