Below is interpreter.java & there's errors in the code, so make sure to fix those errors with the information of what the code must have. Attached is images of the code with errors.      Interpreter.java   import java.util.*;

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
Below is interpreter.java & there's errors in the code, so make sure to fix those errors with the information of what the code must have. Attached is images of the code with errors. 
 
 
Interpreter.java
 
import java.util.*;
 
public class Interpreter {
 
 
 
privateHashMap<String, Object> variables;
 
 
 
publicvoidinterpretFunction(FunctionNode fn){
 
 
 
variables = new HashMap<String, Object>();
 
 
 
for(Node constantNode : fn.getConstants()){
 
Object constant = constantNode.getValue();
 
variables.put(constantNode.getName(), constant);
 
}
 
for(Node localVarNode : fn.getVariables()){
 
Object localVar =null;
 
variables.put(localVarNode.getName(), localVar);
 
}
 
interpretBlock(fn.getStatements(), variables);
 
}
 
 
 
publicvoidinterpretBlock(List<StatementNode> statementNodes,HashMap<String, Object> variables){
 
for(StatementNode statement : statementNodes){
 
if(statement instanceofIfNode){
 
interpretIfNode((IfNode) statement, variables);
 
}elseif(statement instanceofVariableReferenceNode){
 
interpretVariableReferenceNode((VariableReferenceNode) statement, variables);
 
}elseif(statement instanceofMathOpNode){
 
interpretMathOpNode((MathOpNode) statement, variables);
 
}elseif(statement instanceofBooleanCompareNode){
 
interpretBooleanCompareNode((BooleanCompareNode) statement, variables);
 
}elseif(statement instanceofForNode){
 
interpretForNode((ForNode) statement, variables);
 
}elseif(statement instanceofRepeatNode){
 
interpretRepeatNode((RepeatNode) statement, variables);
 
}elseif(statement instanceofConstantNode){
 
interpretConstantNode((ConstantNode) statement, variables);
 
}elseif(statement instanceofWhileNode){
 
interpretWhileNode((WhileNode) statement, variables);
 
}elseif(statement instanceofAssignmentNode){
 
interpretAssignmentNode((AssignmentNode) statement, variables);
 
}elseif(statement instanceofFunctionCallNode){
 
interpretFunctionCallNode((FunctionCallNode) statement, variables);
 
}
 
}
 
}
 
 
 
publicvoidinterpretIfNode(IfNode ifNode,HashMap<String, Object> variables){
 
Object result =expression(ifNode.getBooleanCompare(), variables);
 
if(result !=null&&(result instanceofBoolean&&(Boolean) result)){
 
interpretBlock(ifNode.getStatements(), variables);
 
}elseif(ifNode.getNextIfNode()!=null){
 
interpretIfNode(ifNode.getNextIfNode(), variables);
 
}
 
}
 
 
 
publicObjectinterpretVariableReferenceNode(VariableReferenceNode varRefNode,HashMap<String, Object> variables){
 
String name = varRefNode.getName();
 
if(variables.containsKey(name)){
 
return variables.get(name);
 
}else{
 
thrownewRuntimeException("Variable '"+ name +"' does not exist.");
 
}
 
}
 
 
 
publicObjectinterpretMathOpNode(MathOpNode mathOpNode,HashMap<String, Object> variables){
 
Object leftNode =expression(mathOpNode.getLeft(), variables);
 
Object rightNode =expression(mathOpNode.getRight(), variables);
 
if(!(leftNode instanceofDouble)||!(rightNode instanceofDouble)){
 
thrownewRuntimeException("Cannot add/subtract/multiply/divide/modulo "+ leftNode +" and "+ rightNode);
 
}
 
Double left =(Double) leftNode;
 
Double right =(Double) rightNode;
 
Object result =null;
 
switch(mathOpNode.getOp()){
 
case"+":
 
result = left + right;
 
break;
 
case"-":
 
result = left - right;
 
break;
 
case"*":
 
result = left * right;
 
break;
 
case"/":
 
result = left / right;
 
break;
 
case"%":
 
result = left % right;
 
break;
 
default:
 
thrownewRuntimeException();
}
}
}
 

Comments

None/Excessive (0)

“What” not “Why”, few (5)

Some “what” comments or missing some (7)

Anything not obvious has reasoning (10)

Variable/Function naming

Single letters everywhere (0)

Lots of abbreviations (5)

Full words most of the time (8)

Full words, descriptive (10)

interpretFunction

Not handled(0)

 

 

Creates variables and calls interpretBlock (10)

interpretBlock

Not handled(0)

 

 

Loops over the statement nodes and calls methods for each (5)

expression

Not handled(0)

 

 

Handles mathOpNode, constantNodes, variable references (10)

booleanCompare

Not handled(0)

 

 

Calls expression(), then compares (5)

variableReferenceNode

Not handled(0)

 

 

Looks up nodes and returns IDT (5)

mathOpNode

Not handled(0)

 

 

Calls expression(), then calculates (5)

ifNode

Not handled(0)

 

 

Calls booleanCompare and chains (10)

forNode

Not handled(0)

 

 

Loops over the range and calls interpretBlock(10)

repeatNode

Not handled(0)

 

 

Calls booleanCompare and interpretBlock correctly (5)

constantNodes

Not handled(0)

 

 

Returns a new IDT (5)

whileNode

Not handled(0)

 

 

Calls booleanCompare and interpretBlock correctly (5)

assignmentNode

Not handled(0)

 

 

calls expression() and replaces the IDT entry for the variable(5)

 

1010 public Object interpretMathOpNode (MathOpNode mathOpNode, HashMap<String, Object> variables) {
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 }
130
131}
}
Object leftNode = expression (mathOpNode.getLeft(), variables);
Object rightNode = expression (mathOpNode.getRight(), variables);
if(!(leftNode instanceof Double) || (rightNode instanceof Double)) {
throw new RuntimeException("Cannot add/subtract/multiply/divide/modulo " + leftNode + " and " + ri
}
Double left = (Double) leftNode;
Double right = (Double) rightNode;
Object result = null;
switch (mathOpNode.getOp()) {
case "+":
result left + right;
break;
"_".
case -
result left right;
break;
**".
case www.
result left* right;
break;
case "/":
result left/right;
break;
case "%":
result left % right;
break;
default:
throw new Runtime Exception ("Unrecognized arithmetic operation");
Transcribed Image Text:1010 public Object interpretMathOpNode (MathOpNode mathOpNode, HashMap<String, Object> variables) { 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 } 130 131} } Object leftNode = expression (mathOpNode.getLeft(), variables); Object rightNode = expression (mathOpNode.getRight(), variables); if(!(leftNode instanceof Double) || (rightNode instanceof Double)) { throw new RuntimeException("Cannot add/subtract/multiply/divide/modulo " + leftNode + " and " + ri } Double left = (Double) leftNode; Double right = (Double) rightNode; Object result = null; switch (mathOpNode.getOp()) { case "+": result left + right; break; "_". case - result left right; break; **". case www. result left* right; break; case "/": result left/right; break; case "%": result left % right; break; default: throw new Runtime Exception ("Unrecognized arithmetic operation");
320
33
34
35
36
37
38
39
39 40 41 42 3 44 45 46 7 484958123455 56 7 58 59 60 61
40
41
42
43
44
45
47
48
49
50
52
53
57
public void
interpretBlock(List<StatementNode> statementNodes, HashMap<String, Object> variables) {
for (StatementNode statement : statementNodes) {
if(statement instanceof IfNode) {
59
}
interpretIfNode ((IfNode) statement, variables);
} else if (statement instanceof VariableReferenceNode) {
}
interpretVariableReferenceNode ((VariableReferenceNode) statement, variables);
} else if(statement instanceof MathOpNode) {
interpretMathOpNode ( (MathOpNode) statement, variables);
} else if (statement instanceof BooleanCompareNode) {
interpretBooleanCompareNode((BooleanCompareNode) statement, variables);
else if (statement instanceof ForNode) {
interpretForNode((ForNode) statement, variables);
} else if (statement instanceof RepeatNode) {
interpretRepeatNode ((RepeatNode) statement, variables);
}
} else if(statement instanceof ConstantNode) {
interpretConstantNode((ConstantNode) statement, variables);
} else if (statement instanceof WhileNode) {
interpretWhileNode((WhileNode) statement, variables);
} else if(statement instanceof AssignmentNode) {
interpretAssignmentNode ((AssignmentNode) statement, variables);
} else if (statement instanceof FunctionCallNode) {
interpretFunctionCallNode((FunctionCallNode)
580 private void interpretFunctionCallNode (FunctionCallNode statement, HashMap<String, Object> variables2) {
// TODO Auto-generated method stub
statement, variables);
Transcribed Image Text:320 33 34 35 36 37 38 39 39 40 41 42 3 44 45 46 7 484958123455 56 7 58 59 60 61 40 41 42 43 44 45 47 48 49 50 52 53 57 public void interpretBlock(List<StatementNode> statementNodes, HashMap<String, Object> variables) { for (StatementNode statement : statementNodes) { if(statement instanceof IfNode) { 59 } interpretIfNode ((IfNode) statement, variables); } else if (statement instanceof VariableReferenceNode) { } interpretVariableReferenceNode ((VariableReferenceNode) statement, variables); } else if(statement instanceof MathOpNode) { interpretMathOpNode ( (MathOpNode) statement, variables); } else if (statement instanceof BooleanCompareNode) { interpretBooleanCompareNode((BooleanCompareNode) statement, variables); else if (statement instanceof ForNode) { interpretForNode((ForNode) statement, variables); } else if (statement instanceof RepeatNode) { interpretRepeatNode ((RepeatNode) statement, variables); } } else if(statement instanceof ConstantNode) { interpretConstantNode((ConstantNode) statement, variables); } else if (statement instanceof WhileNode) { interpretWhileNode((WhileNode) statement, variables); } else if(statement instanceof AssignmentNode) { interpretAssignmentNode ((AssignmentNode) statement, variables); } else if (statement instanceof FunctionCallNode) { interpretFunctionCallNode((FunctionCallNode) 580 private void interpretFunctionCallNode (FunctionCallNode statement, HashMap<String, Object> variables2) { // TODO Auto-generated method stub statement, variables);
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Top down approach design
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