Official problem:
Write Java method to perform recursive descent parse of the following production:
<repeat_statement> -> REPEAT <statement> UNTIL <expression> ;
This is what I've come up with:
void repeatStatement() {
if(token == REPEAT) {
token = getNextToken();
if(parseStatement()) {
if(token == UNTIL) {
token = getNextToken();
if(parseExpression()) {
if(token == ;) {
return true
}
}
}
} return false
}
I'm pretty confident that I have the general idea here, but I was hoping that someone could help me polish this/ confirm that I'm on the right track.
It looks (vaguely) like you're trying to evaluate the repeat statement. That's not what recursive descent parsing does. I'd expect something like this (in pseudocode):