Search code examples
regexprologlogic-programming

Are regular expressions an example of logic programming?


I'm just wondering if regular expressions fit into the definition of what Logic Programming is. It is a set of rules which given a set of facts yields a result depending on how the query is asked. To me that sounds like it should fall under Logic Programming but I am not sure.

Thanks!


Solution

  • Are finite state machines an example of imperative programming?

    Regular expressions and logic programs definitely have one thing in common: Both have a natural declarative reading, and you can readily ask and answer:

    What is being described?

    Using a sufficiently expressive logic programming language (and Prolog definitely falls in that category), it is easy to describe what a given regular expression means.

    However, you will need some serious extensions to regular expressions in order to obtain a Turing-complete programming language or even something going beyond just regular languages.