syntax - prolog,非常简单的dcg语法

标签 syntax prolog dcg

我试图理解 prolog 和 dcg 的基本语法,但是很难获得有关真正基本内容的正确信息。看看下面的代码,我基本上只是想实现这样的目标:

Output = te(a, st).

Code: 
    test(te(X,Y)) --> [X], test2(Y).
    test2(st(_X)) --> [bonk]. 

    ?- test(Output, [a, bonk],[]).
    Output = te(a, st(_G6369)). 

我想做的就是在末尾添加单词“st”,我最接近的方法就是这样做,但不幸的是 st 后面跟着一堆废话,很可能是因为单例_X。我只是希望我的 Output 包含类似:te(a, st).

最佳答案

如果您想接受[Term, bonk]形式的输入并获取te(Term,st),您应该更改test/2 code> 接受 bonk 返回 st:

test(te(X,Y)) --> [X], test2(Y).
test2(st) --> [bonk].


?-  test(Output, [a, bonk],[]).
Output = te(a, st).

关于syntax - prolog,非常简单的dcg语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13957146/

相关文章:

machine-learning - Prolog 中可以进行自适应解析吗?

python - 使用 sklearn 和线性回归时出错 : shapes (1, 16) 和 (1,1) 未对齐 : 16 (dim 1) ! = 1 (dim 0)

Javascript、getElementById 和样式不起作用 : Uncaught TypeError: Cannot read property 'style' of null

regex - Vim 语法文件与\zs 不匹配

dictionary - Prolog:如何将字典的负索引转换为最大索引的正后继者?

prolog - 将字符串转换为序言中的列表

database - Prolog 做一个查询

prolog - CFG 的扩展,是什么?

sql-server-2008 - SQLServer 空间查询返回错误在预期条件的上下文中指定的非 bool 类型的表达式,接近 ')'

regex - 将奇数和偶数正则表达式结合到正则语法中?