Q.consider the following code that uses a simple recursive descent parse to vali
ID: 3704127 • Letter: Q
Question
Q.consider the following code that uses a simple recursive descent parse to validates arithmetic expression. Notice the T() method missing. Create the missing T() method.
plz solve it thank you
15. Consider the following code that uses a simple recursive descent pars Notice the T() method missing. Create the missing T() method. // simple recursive descent parser Vo P -E' ET( T F EI digit I letter public class rd t char c; inputBuffer buffer new inputBuffer) bo public static void main (String argvI) System.out.print( Expression ending with n"): rd go new rd); while (true) go.P) void P) ( scan) E O: if(c ';') System.out.print(" accepted "); void E) TO: while isin c. )) scan): TO: void F) if (Character.isDigit(c) I1 Character.isletter (c)) scan) else if (c '(') { scan): E O: if(c= else scan ( ) ; error ("expected ')') )) ) else error ("found + expected letter or digit"): void error (String msg) System.out.println(msg) System.exit (1);Explanation / Answer
Here you go champ. We can easily derive the function T by following the steps:
First call F() to consume F
then check if c is any of the symbol (*, /, %)
if c matches with any of the character, consume the char and call F again
CODE:
void T() {
F();
while ( isin( c, "/%*" ) ) {
scan();
F();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.