EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
Question
Please help me do this exercise
Transcribed Image Text:Programming Exercise:
Using Java, complete the CodeWriter class (part of the overall compiler) which has a
single public method (you may have several private helper methods) that takes in a
String expression and outputs the corresponding pseudo VM code (to the console),
according to the algorithm below:
Page
source code
codewrite(exp):
if exp is a number n:
output "push n"
stack-machine code
push x
x + g(2,y,-z) * 5
if exp is a variable var:
output "push var"
resulting
code
push 2
push y
push z
neg
if exp is "exp, op exp":
codewrite(exp1).
codewrite (exp2),
output "op"
if exp is "op exp":
codeWrite(exp),
output "op"
if exp is "f (exp, exp2, ...)":
codeWrite(exp1),
codewrite(exp).
output "call"
call g
push 5
You may use the following API design to help guide your work, or choose to implement
your own design. Note, since the class is named CodeWriter, I changed the method
name to writeCode (instead of codeWrite, as it is confusing otherwise).
CodeWriter
Class
Fields
a exp: string
Methods
CodeWriter(string exp)
0 main(string[] args): void
writeCode(string exp): void
Finally, here are several test expressions you can use to verify the output of your
CodeWriter.
String testExp1 = "x + -y - z + 5";
String testExp2
=
"f(x, y) * z + 2";
>
1
of 2
---------
- ZOOM
+
SAVE
AI-Generated Solution
info
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
bartleby
Unlock instant AI solutions
Tap the button
to generate a solution
to generate a solution
Click the button to generate
a solution
a solution
Knowledge Booster
Background pattern image
Recommended textbooks for you
- Text book imageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTText book imageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningText book imageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Text book imageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrText book imageProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageText book imageSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning