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
icon
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.
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
steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
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.
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education