GIT> = 0|1|2|3 |4|5 |6|7|8|9|A |B|C Instead of writing 3*2, in this language you write *32 (which evaluates to 6). EXP stands for expressions. means multiply the two digits that follow (after evaluation) so *24 is 8 and *5*34 is 60 as it first multiples 3 and 4 to get answer 12 then multiplies 5 and 12 to get 60. Tn means add the next 3 numbers from n (so eg T3 means 3+4+5=12, T7 means 7+8+9-24), DIGIT gives a way to express numbers up to 12 as a single digit (so A means 10, B means 11, C means 12). Only single digits are allowed and spaces are not allowed. Further legal expressions can be seen below. An example run of the program (characters in bold are typed in by the user and pop-up boxes may be used for input and output):
GIT> = 0|1|2|3 |4|5 |6|7|8|9|A |B|C Instead of writing 3*2, in this language you write *32 (which evaluates to 6). EXP stands for expressions. means multiply the two digits that follow (after evaluation) so *24 is 8 and *5*34 is 60 as it first multiples 3 and 4 to get answer 12 then multiplies 5 and 12 to get 60. Tn means add the next 3 numbers from n (so eg T3 means 3+4+5=12, T7 means 7+8+9-24), DIGIT gives a way to express numbers up to 12 as a single digit (so A means 10, B means 11, C means 12). Only single digits are allowed and spaces are not allowed. Further legal expressions can be seen below. An example run of the program (characters in bold are typed in by the user and pop-up boxes may be used for input and output):
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
![Recursive Parsing Calculator
HINT: Before attempting this exercise, see the simplerecursiveparser.java in the example programs of the
recursion unit on QM+ and the related booklet about Language, grammars and recursion that explains it.
Write a program that recursively parses expressions, input as strings, from the following recursively defined
language and calculates and prints out the answer to the calculations. Legal expressions in this language
involve putting the operator before its arguments (this is called Polish notation).
<EXP>=
* <DIGIT><EXP> | T<EXP <DIGIT>
<DIGIT>=
0|1|2|3|4|5|6|7|8|9|A|B|C
Instead of writing 3*2, in this language you write *32 (which evaluates to 6). EXP stands for expressions.
means multiply the two digits that follow (after evaluation) so *24 is 8 and *5*34 is 60 as it first multiples 3
and 4 to get answer 12 then multiplies 5 and 12 to get 60. Tn means add the next 3 numbers from n (so eg T3
means 3+4+5=12, T7 means 7+8+9-24), DIGIT gives a way to express numbers up to 12 as a sıngle digit
(so A means 10, B means 11, C means 12).
Only single digits are allowed and spaces are not allowed. Further legal expressions can be seen below.
An example run of the program (characters in bold are typed in by the user and
for
pop-up
boxes
may be used
input and output):
Please input the expression B
The answer is 1
Another example run:
Please input the expression T4
The answer is 15
Another example run:
Please input the expression T*23
The answer is 21
Another example run:
Please input the expression T*2*1T2
The answer is 57
Another example run:
Please input the expression *2*3*A5
The answer is 300
Make sure you split the program in to multiple methods, and use a series of recursive methods following the
structure of the recursive definition about expressions. You must not use an explicit loop at all in your
program. Comment your program with useful comments that give useful information, with every method
commented with what it does, use indentation consistently and ensure that your variable names convey
useful information. Your variables should be positioned so that their scope is small.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F390ab119-6217-450a-9cfe-905bc8e62b8f%2F326167f7-8e2f-400d-adca-3a17b137cdc4%2Fkc6zy07_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Recursive Parsing Calculator
HINT: Before attempting this exercise, see the simplerecursiveparser.java in the example programs of the
recursion unit on QM+ and the related booklet about Language, grammars and recursion that explains it.
Write a program that recursively parses expressions, input as strings, from the following recursively defined
language and calculates and prints out the answer to the calculations. Legal expressions in this language
involve putting the operator before its arguments (this is called Polish notation).
<EXP>=
* <DIGIT><EXP> | T<EXP <DIGIT>
<DIGIT>=
0|1|2|3|4|5|6|7|8|9|A|B|C
Instead of writing 3*2, in this language you write *32 (which evaluates to 6). EXP stands for expressions.
means multiply the two digits that follow (after evaluation) so *24 is 8 and *5*34 is 60 as it first multiples 3
and 4 to get answer 12 then multiplies 5 and 12 to get 60. Tn means add the next 3 numbers from n (so eg T3
means 3+4+5=12, T7 means 7+8+9-24), DIGIT gives a way to express numbers up to 12 as a sıngle digit
(so A means 10, B means 11, C means 12).
Only single digits are allowed and spaces are not allowed. Further legal expressions can be seen below.
An example run of the program (characters in bold are typed in by the user and
for
pop-up
boxes
may be used
input and output):
Please input the expression B
The answer is 1
Another example run:
Please input the expression T4
The answer is 15
Another example run:
Please input the expression T*23
The answer is 21
Another example run:
Please input the expression T*2*1T2
The answer is 57
Another example run:
Please input the expression *2*3*A5
The answer is 300
Make sure you split the program in to multiple methods, and use a series of recursive methods following the
structure of the recursive definition about expressions. You must not use an explicit loop at all in your
program. Comment your program with useful comments that give useful information, with every method
commented with what it does, use indentation consistently and ensure that your variable names convey
useful information. Your variables should be positioned so that their scope is small.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 5 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education