Question
Java Programming: Below is the ProgramNode extends Node.java file. There are errors in the code so please fix those errors. There must be no errors
Java Programming: Below is the ProgramNode extends Node.java file. There are errors in the code so please fix those errors. There must be no errors at all. Attached is the rubric that is circled in black all the components the ProgramNode extends Node.java file must have.
public class ProgramNode extends Node {
private Map
public ProgramNode(Map
this.functions = functions;
}
public Map
return functions;
}
public void setFunctions(Map
this.functions = functions;
}
public String toString() {
return "ProgramNode [functions=" + functions + "]";
}
public FunctionNode function() {
if(checkToken("define")) {
nextToken();
String name = getToken(TokenType.IDENTIFIER);
nextToken();
if(checkToken("(")) {
nextToken();
List
if(checkToken(")")) {
nextToken();
if(checkToken(TokenType.END_OF_LINE)) {
nextToken();
List
List
if(checkToken(TokenType.INDENT)) {
nextToken();
List
while(true) {
StatementNode statement = expression();
if(statement == null) {
break;
} else {
statements.add(statement);
}
}
if(checkToken(TokenType.DEDENT)) {
nextToken();
return new FunctionNode(name, parameters, constants, variables, statements);
}
}
}
}
}
}
return null;
}
public List
List
while(true) {
if(checkToken("var")) {
nextToken();
boolean changeable = true;
} else {
boolean changeable = false;
}
String name = getToken(TokenType.IDENTIFIER);
nextToken();
Node type = factor();
if(type == null) {
break;
}
VariableNode variable = new VariableNode(name, changeable, type);
parameters.add(variable);
if(checkToken(",")) {
nextToken();
} else {
break;
}
}
return parameters;
}
public List
List
while(true) {
if(checkToken("const")) {
nextToken();
}
String name = getToken(TokenType.IDENTIFIER);
nextToken();
Node type = factor();
if(type == null) {
break;
}
VariableNode constant = new VariableNode(name, false, type);
constants.add(constant);
if(checkToken(",")) {
nextToken();
} else {
break;
}
}
return constants;
}
public List
List
while(true) {
if(checkToken("var")) {
nextToken();
}
String name = getToken(TokenType.IDENTIFIER);
nextToken();
Node type = factor();
if(type == null) {
break;
}
VariableNode variable = new VariableNode(name, true, type);
variables.add(variable);
if(checkToken(",")) {
nextToken();
} else {
break;
}
}
return variables;
}
public ProgramNode parse() {
Map
while(true) {
FunctionNode function = function();
if(function == null) {
break;
} else {
functions.put(function.getName(), function);
}
}
return new ProgramNode(functions);
}
public static void main(String[] args) {
ProgramNode program = parse();
for(FunctionNode function : program.getFunctions().values()) {
System.out.println(function);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started