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 functions;

public ProgramNode(Map functions) {

this.functions = functions;

}

public Map getFunctions() {

return functions;

}

public void setFunctions(Map functions) {

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 parameters = parameterDeclarations();

if(checkToken(")")) {

nextToken();

if(checkToken(TokenType.END_OF_LINE)) {

nextToken();

List constants = constantDeclarations();

List variables = variableDeclarations();

if(checkToken(TokenType.INDENT)) {

nextToken();

List statements = new ArrayList();

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 parameterDeclarations() {

List parameters = new ArrayList();

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 constantDeclarations() {

List constants = new ArrayList();

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 variableDeclarations() {

List variables = new ArrayList();

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 functions = new HashMap();

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);

}

}

}

Java Programming: Below is the ProgramNode extends Node.java file. There are errors

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!