简体   繁体   English

使用Scheme中的DCG进行解析(不使用Prolog)?

[英]Parsing with DCGs in Scheme (without Prolog)?

Lots of Prolog-in-Scheme implementations are out there. 很多Prolog-in-Scheme实施都在那里。 Eg Kanren, Schelog. 例如Kanren,Schelog。

Apparently in "Paradigms of AI Programming" Norvig implements Prolog-to-Lisp compiler in Lisp in order to use Definite Clause Grammars. 显然,在“AI编程的范例”中,Norvig在Lisp中实现了Prolog-to-Lisp编译器,以便使用Definite Clause Grammars。

But is there a simpler cleaner way? 但是有更简单的清洁方式吗? Maybe some clever use of amb to avoid implementing a full "Prolog"? 也许一些聪明的使用amb来避免实施完整的“Prolog”? What is the easiest way to have DCG-based parsing in Scheme? 在Scheme中进行基于DCG的解析的最简单方法是什么?

DCGs use both unification and backtracking, so there's no avoiding implementing the core of Prolog. DCG使用统一和回溯,所以没有避免实现Prolog的核心。 That is, you can represent any pure Prolog program as a DCG parsing the empty list. 也就是说,您可以将任何纯Prolog程序表示为解析空列表的DCG。

You might do it if you only care about some special case of DCGs, like ones without variables (good only for recognizing, not parsing). 如果您只关心DCG的一些特殊情况,例如没有变量的DCG(仅适用于识别,而不是解析),您可以这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM