我不习惯功能性编程,并且很难为每个循环找出一个简单的方法。对于每个XSL - 变量?递归?
我有这个手,我需要在xsl中使用相同的算法。
let the input be a string S consisting of n characters: a1 ... an.
let the grammar contain r nonterminal symbols R1 ... Rr.
This grammar contains the subset Rs which is the set of start symbols.
let P[n,n,r] be an array of booleans. Initialize all elements of P to false.
for each i = 1 to n
for each unit production Rj -> ai
set P[i,1,j] = true
for each i = 2 to n -- Length of span
for each j = 1 to n-i+1 -- Start of span
for each k = 1 to i-1 -- Partition of span
for each production RA -> RB RC
if P[j,k,B] and P[j+k,i-k,C] then set P[j,i,A] = true
if any of P[1,n,x] is true (x is iterated over the set s, where s are all the indices for Rs) then
S is member of language
else
S is not member of language
我能够做一些,但我觉得卡住,走错了路。
我了解到我不能拥有类似数组的东西。即使我创建一个变量,就像一个数组,我无法更新它。
所以我开始做一些递归(通过调用模板),但我仍然认为,如果这是正确的方式。如果还有另一个为什么要实现那些没有递归嵌套每个。
你是对的:从程序算法的描述逆向工程一个功能程序是很困难的。抛弃算法通常要好得多,并从描述算法的目标开始。 –