Maybe this'll do it:
Code:
syntaxTokenList = new Array(0);
syntaxTokenPoint = new Array(0);
// Make a buffer of all the syntax characters, along with their positions in the text
for (parserIndex = 0; parserIndex < Input.length; parserIndex++) {
if (Input.charAt(parserIndex) == "," || Input.charAt(parserIndex) == "."
|| Input.charAt(parserIndex) == "?" || Input.charAt(parserIndex) == "!"
|| Input.charAt(parserIndex) == ":" || Input.charAt(parserIndex) == ";") {
// Store the syntax character
syntaxTokenList[syntaxTokenIndex] = Input.charAt(parserIndex);
syntaxTokenPoint[syntaxTokenIndex] = parserIndex;
syntaxTokenIndex++;
// Replace the syntax character with a space.
Input1 = Input.substring(0, parserIndex);
Input2 = Input.substring(parserIndex + 1);
Input = Input 1 + " " + Input2;
}
}
This is getting complicated.
Here's the parser.
Code:
tokenList = new Array(0);
for (parserIndex = 0; parserIndex < Input.length; parserIndex++) {
if (Input.charAt(parserIndex) == " ") {
if (Input.charAt(parserIndex - 1) != " ") {
tokenIndex++;
}
}
else {
tokenList[tokenIndex] =
tokenList[tokenIndex + Input.charAt(parserIndex);
}
}
I'd say a regular expression could have eliminated most of the syntax code, but I digress.
Now I'm wondering how to put the elements in with the reinstated syntax. (to restore the information to readability.) Si, you tricksy fox.
Let's put 'em together.
Code:
for (parserIndex = 0; parserIndex < Input.length; parserIndex++) {
if (Input.charAt(parserIndex) == "," || Input.charAt(parserIndex) == "."
|| Input.charAt(parserIndex) == "?" || Input.charAt(parserIndex) == "!"
|| Input.charAt(parserIndex) == ":" || Input.charAt(parserIndex) == ";") {
// Store the syntax character
syntaxTokenList[syntaxTokenIndex] = Input.charAt(parserIndex);
syntaxTokenPoint[syntaxTokenIndex] = parserIndex;
syntaxTokenAssociate[syntaxTokenIndex] = tokenIndex;
syntaxTokenIndex++;
// Replace the syntax character with a space.
Input1 = Input.substring(0, parserIndex);
Input2 = Input.substring(parserIndex + 1);
Input = Input 1 + " " + Input2;
}
if (Input.charAt(parserIndex) == " ") {
if (Input.charAt(parserIndex - 1) != " ") {
tokenIndex++;
}
}
else {
tokenList[tokenIndex] =
tokenList[tokenIndex + Input.charAt(parserIndex);
}
}
Which puts us in position to conduct the following solution:
Code:
for (tokenIndex = 0; tokenIndex < tokenList.length; index++) {
for (vocabIndex = 0; vocabIndex < vocab.length; vocabIndex++)
if (tokenList[index] == ElementCorrespondenceTable[vocabIndex]) {
Output = Output + tokenList[index] + ElementCorrespondenceTable[vocabIndex];
while (syntaxTokenAssociate[syntaxTokenIndex] == tokenIndex)
Output = Output + syntaxTokenList[syntaxTokenIndex];
syntaxTokenIndex++;
}
}
}
}
Not complete by any means (ellipsis, for example, would not remain solid), but it'll do for a test, I think. (nevermind, changing "if" to "while" did the trick.)