Question: 11. Prepare a program in Java for parser (parse.java). Introduction: A recursive-descent parser has a subprogram for each nonterminal in its associated grammar. When given

 11. Prepare a program in Java for parser (parse.java). Introduction: A

11. Prepare a program in Java for parser (parse.java). Introduction: A recursive-descent parser has a subprogram for each nonterminal in its associated grammar. When given an input string, it traces out the parse tree that can be rooted at that nonterminal and whose leaves match the input string. This program evaluates standard expressions typed in by the user. The expressions can use positive real numbers and the binary operators +,,, and /. Consider the grammar: expr->term { | '-' term } term- >{/ factor } factor- > number } mid expr( ){ term() while ( token="=") \{ match("'+", "expected"); term(); \} Design: The steps: 1.Read an expression from the current line of input and return its value. 2.Read a term from the current line of input and return its value. 3. Read a factor from the current line of input and return its value. Use Java and from the stream to get tokens. Input: Expressions will be inserted from console: 1. 2+3+4 2. 234 3. 6/3 Output (test) 1. 2+3+4=9 2. 234=24 3. 6/3=2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!