dcg-semicontext

Applying semicontext notation for passing additional arguments

拜拜、爱过 提交于 2020-01-21 12:17:08
问题 This is a follow-on question from an earlier question from Mat's answer Starting with this e([number(0)] , t1 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([number(1)] , t2 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([number(2)] , t3 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([op(neg),[Arg]] , u1(E) , [_|Uc0], Uc1, Bc0 , Bc1) --> [_], e(Arg , E , Uc0, Uc1, Bc0, Bc1). e([op(ln),[Arg]] , u2(E) , [_|Uc0], Uc1, Bc0 , Bc1) --> [_], e(Arg , E , Uc0, Uc1, Bc0, Bc1). e([op(add),[Left,Right]], b1(E0,E1) , Uc0 , Uc2, [_|Bc0], Bc2) -

Extension to CFG, what is it?

限于喜欢 提交于 2019-12-19 02:22:19
问题 Consider the following extension to context-free grammars that permits rules to have in the left-hand side, one (or more) terminal on the right side of the non-terminal. That is, rules of the form: A b -> ... The right-hand side may be anything, like in context-free grammars. In particular, it is not required, that the right-hand side will have exactly the same terminal symbol at the end. In that case, this extension would be context-sensitive. But the terminal is not just a context.

Dcg state implementation of algorithm

浪子不回头ぞ 提交于 2019-12-11 05:57:37
问题 The distance between a long sequence and a short sequence, is the minimum distance between the short sequence and any subsequence of the long sequence that is the same length as the short sequence. The distance I am using is I think the Manhattan distance . (But this should be unimportant as I would like to be able to change distance functions). This first version shows a naive implementation without early abandon. I generate all subsequence of the same length, map these to find the distance

Translation to DCG Semicontext not working

末鹿安然 提交于 2019-12-02 09:06:35
问题 Since this question uses list, I wanted to solve it using DCG. In the process I realized that semicontext could be used. (DCG Primer) The original problem is to return count of items in a list but if two identical items are next to each other then don't increment the count. While my code works for some of the test cases, it fails for others. It is just one clause that is failing. In looking at the code with a debugger it appears that the second state variable, the returned list, is bound upon

Translation to DCG Semicontext not working - follow on

断了今生、忘了曾经 提交于 2019-12-02 04:50:50
问题 As a follow up to this question which poses the problem Return count of items in a list but if two identical items are next to each other then don't increment the count. This code is the closest I came to solving this with DCG and semicontext. lookahead(C),[C] --> [C]. % empty list % No lookahead needed because last item in list. count_dcg(N,N) --> []. % single item in list % No lookahead needed because only one in list. count_dcg(N0,N) --> [_], \+ [_], { N is N0 + 1 }. % Lookahead needed

Translation to DCG Semicontext not working - follow on

旧巷老猫 提交于 2019-12-02 00:51:04
As a follow up to this question which poses the problem Return count of items in a list but if two identical items are next to each other then don't increment the count. This code is the closest I came to solving this with DCG and semicontext. lookahead(C),[C] --> [C]. % empty list % No lookahead needed because last item in list. count_dcg(N,N) --> []. % single item in list % No lookahead needed because only one in list. count_dcg(N0,N) --> [_], \+ [_], { N is N0 + 1 }. % Lookahead needed because two items in list and % only want to remove first item. count_dcg(N0,N) --> [C1], lookahead(C2), {

Applying semicontext notation for passing additional arguments

偶尔善良 提交于 2019-12-01 21:36:45
This is a follow-on question from an earlier question from Mat's answer Starting with this e([number(0)] , t1 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([number(1)] , t2 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([number(2)] , t3 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([op(neg),[Arg]] , u1(E) , [_|Uc0], Uc1, Bc0 , Bc1) --> [_], e(Arg , E , Uc0, Uc1, Bc0, Bc1). e([op(ln),[Arg]] , u2(E) , [_|Uc0], Uc1, Bc0 , Bc1) --> [_], e(Arg , E , Uc0, Uc1, Bc0, Bc1). e([op(add),[Left,Right]], b1(E0,E1) , Uc0 , Uc2, [_|Bc0], Bc2) --> [_,_], e(Left, E0, Uc0, Uc1, Bc0, Bc1), e(Right, E1, Uc1, Uc2, Bc1, Bc2). e([op(sub),[Left,Right]],

Extension to CFG, what is it?

耗尽温柔 提交于 2019-11-30 19:44:15
Consider the following extension to context-free grammars that permits rules to have in the left-hand side, one (or more) terminal on the right side of the non-terminal. That is, rules of the form: A b -> ... The right-hand side may be anything, like in context-free grammars. In particular, it is not required, that the right-hand side will have exactly the same terminal symbol at the end. In that case, this extension would be context-sensitive. But the terminal is not just a context. Sometimes, this terminal is called "pushback". Clearly, this is no longer CFG (type-2). It includes type-1. But