summaryrefslogtreecommitdiff
path: root/Homework/cs5300/compiler/submit/ast/BinaryOperator.java
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
commit6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 (patch)
treeed97e39ec77c5231ffd2c394493e68d00ddac5a4 /Homework/cs5300/compiler/submit/ast/BinaryOperator.java
downloadmisc-undergrad-6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6.tar.gz
misc-undergrad-6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6.zip
Diffstat (limited to 'Homework/cs5300/compiler/submit/ast/BinaryOperator.java')
-rw-r--r--Homework/cs5300/compiler/submit/ast/BinaryOperator.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/Homework/cs5300/compiler/submit/ast/BinaryOperator.java b/Homework/cs5300/compiler/submit/ast/BinaryOperator.java
new file mode 100644
index 0000000..747b3ba
--- /dev/null
+++ b/Homework/cs5300/compiler/submit/ast/BinaryOperator.java
@@ -0,0 +1,35 @@
+/*
+ * Code formatter project
+ * CS 4481
+ */
+package submit.ast;
+
+/**
+ *
+ * @author edwajohn
+ */
+public class BinaryOperator implements Expression {
+
+ private final Expression lhs, rhs;
+ private final BinaryOperatorType type;
+
+ public BinaryOperator(Expression lhs, BinaryOperatorType type, Expression rhs) {
+ this.lhs = lhs;
+ this.type = type;
+ this.rhs = rhs;
+ }
+
+ public BinaryOperator(Expression lhs, String type, Expression rhs) {
+ this.lhs = lhs;
+ this.type = BinaryOperatorType.fromString(type);
+ this.rhs = rhs;
+ }
+
+ @Override
+ public void toCminus(StringBuilder builder, String prefix) {
+ lhs.toCminus(builder, prefix);
+ builder.append(" ").append(type).append(" ");
+ rhs.toCminus(builder, prefix);
+ }
+
+}