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.