3 ms·
Some background on why Prolog for parsing: That was traditionally a popular use of Prolog, because something similar to BNF-style grammar rules can be written a
by mjn 11y ago
Some background on why Prolog for parsing: That was traditionally a popular use of Prolog, because something similar to BNF-style grammar rules can be written almost literally as Prolog clauses, and you get a parser for "free". Very easy to prototype, plus since it's just Prolog clauses that can be used by the rest of the Prolog program and vice versa (not black-box tables generated by YACC), you can muck with edge cases, integrate error reporting, call out to information-extraction heuristics where relevant, etc. The technique is "definite clause grammars" (DCGs), and can either be written directly in normal Prolog, or with some syntactic sugar that most Prolog implementations include. Here's a tutorial: http://www.pathwayslms.com/swipltuts/dcg/ http://www.pathwayslms.com/swipltuts/dcg/
Compared to when DCG parsing was most popular ('70s-'90s), there are now more alternatives for easily working with grammars, though, including non-black-box approaches nicely integrated into languages, like combinator parsers in Haskell and LPeg in Lua. So it's not quite as unique today, though it's still a nice way to prototype parsers.