From 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:55:17 -0700 Subject: Init --- .../compiler/p5-compiler/submit/ast/Program.java | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Homework/cs5300/compiler/p5-compiler/submit/ast/Program.java (limited to 'Homework/cs5300/compiler/p5-compiler/submit/ast/Program.java') diff --git a/Homework/cs5300/compiler/p5-compiler/submit/ast/Program.java b/Homework/cs5300/compiler/p5-compiler/submit/ast/Program.java new file mode 100644 index 0000000..e32a7d2 --- /dev/null +++ b/Homework/cs5300/compiler/p5-compiler/submit/ast/Program.java @@ -0,0 +1,50 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; +import submit.MIPSResult; +import submit.RegisterAllocator; +import submit.SymbolTable; + +/** + * + * @author edwajohn + */ +public class Program extends AbstractNode implements Node { + + private ArrayList declarations; + + public Program(List declarations) { + this.declarations = new ArrayList<>(declarations); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + toCminus(builder, ""); + return builder.toString(); + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + for (Declaration declaration : declarations) { + declaration.toCminus(builder, ""); + } + } + + @Override + public MIPSResult toMIPS(StringBuilder code, StringBuilder data, + SymbolTable symbolTable, + RegisterAllocator registerAllocator) { + // Store newline in .data + data.append("newline: .asciiz \"\\n\"\n"); + + for (Declaration declaration : declarations) + declaration.toMIPS(code, data, symbolTable, registerAllocator); + return MIPSResult.createVoidResult(); + } +} -- cgit v1.3