Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the BNF for a regex (in order to write a full or partial parser)

Tags:

regex

bnf

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.

like image 788
peter.murray.rust Avatar asked Sep 16 '09 20:09

peter.murray.rust


2 Answers

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

like image 66
Vinko Vrsalovic Avatar answered Oct 17 '22 16:10

Vinko Vrsalovic


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

like image 36
RMorrisey Avatar answered Oct 17 '22 16:10

RMorrisey