Alex Rivera | Logout

Are regular expressions used to build parsers?

Asked 2010-08-15T11:04:27.510
14

This is just a question out of curiosity since I have been needing to get more and more into parsing and using regex lately.. it seems, for questions I come across in my searches regarding parsing of some sort, someone always ends up saying, when asked something relating to regex, "regex isn't good for that, use such and such parser instead"... as I have come to better understand regex, I think most stuff is possible, just its rather complex and time consuming since you have to account for many different possiblities, and of course, it has to be combined with conditional statements and loops to build any sort of parser.. so I'm wondering if regex is what is used to build most parsers or is there some other method being used.. I am just wondering since I may have the need to build some fairly complex custom parsers coming up where there isn't necessarily an existing one to use.

thanks for any info as I can't seem to find a direct answer to this.

Edit
Report

1 Answer

3

(Most) parsers are created for recursive languages ie. languages that have recursive features. RegExps can't handle recursivity, so they aren't used for parser construction (without extra hacks a la Perl Markdown). However, RegExps are used for developing lexers, as they make life much easier that way.

answered 2010-08-15T11:12:33.737

Your Answer