
Originally Posted by
mickey
hoping it's LL1: the parser must accept things like this below
<send>
<target>
<string name="find"> Primer </string>
</target>
</send>
<send>
<target>
<string name="find"> Primer </string>
</target>
</send>
To copy to clipboard, switch view to plain text mode
Hello,
here I did something like this:
Token nextToken() {
while ( done ) {
char = (char) _data[_pos++]; // I read the entire file into a block of memory
switch (state) {
case 0 : if (ch == '<') state = 1; break;
case 1 : if (ch == 's') state = 2; break;
case 2 : if (ch == 'e') state = 3; break;
case 3 : if (ch == 'n') state = 4; break;
case 4 : if (ch == 'd') state = 5; break;
case 5 : if (ch == '>') state = 6; return OpenSend;
case 6: .......// all other
case n: if (ch == '<') state = n+1; break;
case n+1 : if (ch == '/') state = n+2; break;
//and so on to recognize "send" and ">"
}
}
}
Token nextToken() {
while ( done ) {
char = (char) _data[_pos++]; // I read the entire file into a block of memory
switch (state) {
case 0 : if (ch == '<') state = 1; break;
case 1 : if (ch == 's') state = 2; break;
case 2 : if (ch == 'e') state = 3; break;
case 3 : if (ch == 'n') state = 4; break;
case 4 : if (ch == 'd') state = 5; break;
case 5 : if (ch == '>') state = 6; return OpenSend;
case 6: .......// all other
case n: if (ch == '<') state = n+1; break;
case n+1 : if (ch == '/') state = n+2; break;
//and so on to recognize "send" and ">"
}
}
}
To copy to clipboard, switch view to plain text mode
I wonder: Must I to reconize in the scanner two time the string "send". Is there any tricks to avoid this? ( I mean, I'd like to avoid to write states that recognizes the same "string". I have the same problem with <string></string> and <target></target>).
Hope it's clear...
thanks,
Bookmarks