Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

}

}

}

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago