1

I'm working on an implementation of the CYK parsing algorithm for context free grammars.

However the hard part is I'm required to do this in XSL(A functional language) as opposed to a more procedural one that I'm quite familiar with - like Java.

I have a working implementation of an algorithm in Java but I would like to convert this to Xsl

   public boolean processString(String w) 
   // a string of any length like "aabaaba" or "my cat eats fish"
   {
        int length = w.length();
        table = new ArrayList[length][];
  for (int i = 0; i < length; ++i)
  {
        table[i] = new ArrayList[length];
        for (int j = 0; j < length; ++j)
          table[i][j] = new ArrayList < String > ();
  }
  for (int i = 0; i < length; ++i)
  {
     Set<String> keys = terminals.keySet();
     for (String key : keys)
     {
        if (terminals.get(key).charValue() == w.charAt(i))
           table[i][i].add(key);
     }
  }
  for (int l = 2; l <= length; ++l)
  {
     for (int i = 0; i <= length - l; ++i)
     {
        int j = i + l - 1;
        for (int k = i; k <= j - 1; ++k)
        {
           Set<String> keys = variables.keySet();
           for (String key : keys)
           {
              String[] values = variables.get(key);
              if (table[i][k].contains((values[0]))
                    && table[k + 1][j].contains(values[1]))
                 table[i][j].add(key);
           }
        }
     }
  }
  if (table[0][length - 1].contains(startVariable))
     return true;
  return false;
  }

Any help would be greatly appreciated. Thanks in advance.

  • Consider to post a minimal but complete sample of the input you have and the output you want, together with a minimal but complete sample of code that can be run. That method takes a String and returns a boolean but uses variables like `terminals` or `startVariable` you have nowhere declared nor initialized, so it is not possible to read the code and understand what the code is supposed to do. – Martin Honnen Oct 26 '15 at 18:47
  • 1
    Seems to be a duplicate of: http://stackoverflow.com/questions/33340967/cocke-younger-kasami-cyk-algorithm-in-the-xslt-and-transform-the-xml-to-produc – michael.hor257k Oct 26 '15 at 19:07

0 Answers0