本文介绍了对于每个到 XSL - 变量?递归?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不习惯函数式编程,并且很难为每个循环找出一个简单的方法.

I am not used to functional programming and having hard times figuring out a simple for each loops.

我手头有这个,我需要在 xsl 中修正相同的算法.

I have this in hand and i need to right the same algorithm in 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

我可以做一些事情,但我觉得卡住了,走错了路.

I am able to do some but i feel stuck and going into the wrong way.

我了解到我不能拥有数组之类的东西.即使我创建了一个像数组一样的变量,我也无法更新它.

I learned that I cannot have something like arrays. Even i create a variable which acts like an array i cannot update it.

所以我开始做一些递归(通过调用模板),但我仍然在考虑这是否是正确的方法.如果还有另一个原因,为什么要在没有递归的情况下为 eachs 实现嵌套..

So i started doing some recursions (by calling templates) but i am still thinking if it is the right way. And if there is another why to implement those nested for eachs without recursion..

推荐答案

在 XSLT 中,如果您避免使用 xsl:for-each,情况会好得多.

In XSLT you are much better off if you avoid using xsl:for-each.

您可能想看看我在 2007 年实现的完全用 XSLT 2.0 编写的通用 LR(1) 解析器.它是 FXSL 的一部分,可以在此处查看:http://fxsl.cvs.sourceforge.net/viewvc/fxsl/fxsl-xslt2/f/func-lrParse.xsl?view=markup

我写了两个相当复杂的解析器,一个是针对 JSON 的(见 http://fxsl.cvs.sourceforge.net/viewvc/fxsl/fxsl-xslt2/f/func-json-document.xsl?revision=1.11&view=markup )

I have written two quite complicated parser one is for JSON (see http://fxsl.cvs.sourceforge.net/viewvc/fxsl/fxsl-xslt2/f/func-json-document.xsl?revision=1.11&view=markup )

另一个更复杂的是 XPath 2.0(语法有 209 条规则).

and another, much more complicated, is for XPath 2.0 (the grammar has 209 rules).

一个基本工具是一个经过修改的 YACC,它为特定的 LR(1) 语法生成解析表作为 XML 文档.然后将它们与输入字符串一起提供给通用 LR(1) 解析器的 XSLT 实现.

A basic tool is a modified YACC that produces the parsing tables for a particular LR(1) grammar as XML documents. These are then fed, together with the input string, to the XSLT implementation of the general LR(1) parser.

这篇关于对于每个到 XSL - 变量?递归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 05:01