Write a recursivedescent subprogram for the nonterminal defi

Write a recursive-descent subprogram for the nonterminal defined as below: rightarrow if ()

Solution

private static int valueOfExpr(Queue ts) { //expr->term{add-op term} add-op->+|-

int value = valueOfTerm(ts); // similar to valueOfExpr

while (ts.front().equals(\"+\") || ts.front().equals(\"-\")) { // Look ahead one token in ts to see what\'s next

String op = ts.dequeue(); //consume the next token from ts

if (op.equals(\"+\")) {

value = value + valueOfTerm(ts); //Evaluation

}

else /* \"-\" */ {

value = value - valueOfTerm(ts);

}

}

return value;

}

 Write a recursive-descent subprogram for the nonterminal defined as below: rightarrow if () Solutionprivate static int valueOfExpr(Queue ts) { //expr->term{

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site