summaryrefslogtreecommitdiff
path: root/dice-lang/src/main/java/bjc/dicelang/ast/nodes
diff options
context:
space:
mode:
Diffstat (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/nodes')
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceASTType.java27
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceLiteralNode.java52
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceLiteralType.java18
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceOperatorType.java29
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/IDiceASTNode.java23
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java73
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/IntegerLiteralNode.java50
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/OperatorDiceNode.java110
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/VariableDiceNode.java101
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/package-info.java7
10 files changed, 0 insertions, 490 deletions
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceASTType.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceASTType.java
deleted file mode 100644
index 9feb461..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceASTType.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-/**
- * An enum to represent the type of node an AST node is
- *
- * @author ben
- *
- */
-public enum DiceASTType {
- /**
- * A node that contains a literal value
- */
- LITERAL,
- /**
- * A node that contains an operator expression
- */
- OPERATOR,
- /**
- * A node that contains a variable reference
- */
- VARIABLE;
-
- @Override
- public String toString() {
- return this.name().toLowerCase();
- }
-} \ No newline at end of file
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceLiteralNode.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceLiteralNode.java
deleted file mode 100644
index b398ac6..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceLiteralNode.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-import bjc.dicelang.IDiceExpression;
-
-/**
- * Represents a literal backed by a dice expression
- *
- * @author ben
- *
- */
-public class DiceLiteralNode implements ILiteralDiceNode {
- private IDiceExpression expression;
-
- /**
- * Create a new literal from an expression
- *
- * @param exp
- * The expression to attempt to create a literal from
- */
- public DiceLiteralNode(IDiceExpression exp) {
- expression = exp;
- }
-
- @Override
- public boolean canOptimize() {
- return expression.canOptimize();
- }
-
- @Override
- public DiceLiteralType getLiteralType() {
- return DiceLiteralType.DICE;
- }
-
- /**
- * Return the expression being represented
- *
- * @return The expression being represented
- */
- public IDiceExpression getValue() {
- return expression;
- }
-
- @Override
- public int optimize() {
- return expression.optimize();
- }
-
- @Override
- public String toString() {
- return expression.toString();
- }
-}
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceLiteralType.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceLiteralType.java
deleted file mode 100644
index 41c6b05..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceLiteralType.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-/**
- * Represents the type of literals that can be in an AST
- *
- * @author ben
- *
- */
-public enum DiceLiteralType {
- /**
- * Represents a integral constant
- */
- INTEGER,
- /**
- * Represents a dice literal
- */
- DICE;
-}
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceOperatorType.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceOperatorType.java
deleted file mode 100644
index 7cc1e42..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/DiceOperatorType.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-/**
- * Represents the different type of operators.
- *
- * Mostly, what distinguishes groups is that all the operators in a group
- * have similiar precedence, and operate on similiar things
- *
- * @author ben
- *
- */
-public enum DiceOperatorType {
- /**
- * Represents operators that do math operations
- */
- MATH,
- /**
- * Represents operators that do things with arrays
- */
- ARRAY,
- /**
- * Represents operators that do things with dice
- */
- DICE,
- /**
- * Represents operators that do things with expressions
- */
- EXPRESSION;
-}
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/IDiceASTNode.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/IDiceASTNode.java
deleted file mode 100644
index b7bf9a6..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/IDiceASTNode.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-/**
- * The interface for a node in a dice AST
- *
- * @author ben
- *
- */
-public interface IDiceASTNode {
- /**
- * Get the type of AST node this node is
- *
- * @return The type of AST node this AST node is
- */
- public DiceASTType getType();
-
- /**
- * Check if this node represents an operator or not
- *
- * @return Whether or not this node represents an operator
- */
- public boolean isOperator();
-} \ No newline at end of file
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java
deleted file mode 100644
index b94bcc8..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-/**
- * Represents a literal of some type in the AST
- *
- * @author ben
- *
- */
-public interface ILiteralDiceNode extends IDiceASTNode {
- /**
- * Check if a token represents a literal, and if so, what type
- *
- * @param tok
- * The token to check
- * @return The type the literal would be if it is one, or null
- * otherwise
- */
- static DiceLiteralType getLiteralType(String tok) {
- String diceGroupOrNumber = "[(?:\\d*d\\d+)(?:\\d+)]";
-
- if (tok.matches("\\A" + diceGroupOrNumber + "?" + "c"
- + diceGroupOrNumber + "\\Z")) {
- return DiceLiteralType.DICE;
- }
-
- String diceGroup = "\\d*d\\d+\\";
-
- if (tok.matches("\\A" + diceGroup + "Z")) {
- return DiceLiteralType.DICE;
- }
-
- try {
- Integer.parseInt(tok);
- return DiceLiteralType.INTEGER;
- } catch (@SuppressWarnings("unused") NumberFormatException nfex) {
- // We don't care about details
- return null;
- }
- }
-
- /**
- * Check if this node can be optimized to a constant
- *
- * @return Whether or not this node can be optimized to a constant
- * @see bjc.dicelang.IDiceExpression#canOptimize()
- */
- boolean canOptimize();
-
- /**
- * Get the type of literal this node represents
- *
- * @return The type of literal this node represents
- */
- DiceLiteralType getLiteralType();
-
- @Override
- default DiceASTType getType() {
- return DiceASTType.LITERAL;
- }
-
- @Override
- default boolean isOperator() {
- return false;
- }
-
- /**
- * Optimize this node to a constant if possible
- *
- * @return This node in constant form if possible
- * @see bjc.dicelang.IDiceExpression#optimize()
- */
- int optimize();
-}
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/IntegerLiteralNode.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/IntegerLiteralNode.java
deleted file mode 100644
index 3d43bb1..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/IntegerLiteralNode.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-/**
- * Represents an integer literal of some kind
- *
- * @author ben
- *
- */
-public class IntegerLiteralNode implements ILiteralDiceNode {
- private int value;
-
- /**
- * Create a new integer literal from the given number
- *
- * @param val
- * The value this node represents
- */
- public IntegerLiteralNode(int val) {
- value = val;
- }
-
- @Override
- public boolean canOptimize() {
- return true;
- }
-
- @Override
- public DiceLiteralType getLiteralType() {
- return DiceLiteralType.INTEGER;
- }
-
- /**
- * Get the value this node represents
- *
- * @return The integer value of this node
- */
- public int getValue() {
- return value;
- }
-
- @Override
- public int optimize() {
- return value;
- }
-
- @Override
- public String toString() {
- return Integer.toString(value);
- }
-}
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/OperatorDiceNode.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/OperatorDiceNode.java
deleted file mode 100644
index 7c0a29d..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/OperatorDiceNode.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-import static bjc.dicelang.ast.nodes.DiceOperatorType.DICE;
-import static bjc.dicelang.ast.nodes.DiceOperatorType.EXPRESSION;
-import static bjc.dicelang.ast.nodes.DiceOperatorType.MATH;
-
-/**
- * A node that represents an operator
- *
- * @author ben
- *
- */
-public enum OperatorDiceNode implements IDiceASTNode {
- /**
- * Represents adding two nodes
- */
- ADD(MATH),
- /**
- * Represents dividing two nodes
- */
- DIVIDE(MATH),
- /**
- * Represents multiplying two nodes
- */
- MULTIPLY(MATH),
- /**
- * Represents subtracting two nodes
- */
- SUBTRACT(MATH),
- /**
- * Representings combining two node values together
- */
- COMPOUND(DICE),
- /**
- * Represents using one node a variable number of times
- */
- GROUP(DICE),
- /**
- * Represents constructing an array from a sequence of expressions
- */
- ARRAY(DiceOperatorType.ARRAY),
- /**
- * Represents assigning one node to another
- */
- ASSIGN(EXPRESSION),
- /**
- * Represents evaluating one expression in the context of another
- */
- LET(EXPRESSION);
-
- /**
- * Create a operator node from a string
- *
- * @param s
- * The string to convert to a node
- * @return The operator corresponding to the node
- */
- public static OperatorDiceNode fromString(String s) {
- switch (s) {
- case ":=":
- return ASSIGN;
- case "+":
- return ADD;
- case "-":
- return SUBTRACT;
- case "*":
- return MULTIPLY;
- case "/":
- return DIVIDE;
- case "d":
- case "group":
- return GROUP;
- case "c":
- case "compound":
- return COMPOUND;
- case "=>":
- return LET;
- case "[]":
- return ARRAY;
- default:
- throw new IllegalArgumentException(
- s + " is not a valid operator node");
- }
- }
-
- /**
- * Represents the group of operator this operator is sorted into.
- *
- */
- public final DiceOperatorType type;
-
- private OperatorDiceNode(DiceOperatorType ty) {
- type = ty;
- }
-
- @Override
- public DiceASTType getType() {
- return DiceASTType.OPERATOR;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see bjc.utils.dice.ast.IDiceASTNode#isOperator()
- */
- @Override
- public boolean isOperator() {
- return true;
- }
-}
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/VariableDiceNode.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/VariableDiceNode.java
deleted file mode 100644
index da66608..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/VariableDiceNode.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-/**
- * A node that represents a reference to a variable
- *
- * @author ben
- *
- */
-public class VariableDiceNode implements IDiceASTNode {
- /**
- * The variable referenced by this node
- */
- private String variableName;
-
- /**
- * Create a new node representing the specified variable
- *
- * @param varName
- * The name of the variable being referenced
- */
- public VariableDiceNode(String varName) {
- this.variableName = varName;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- // Handle special cases
- if (this == obj) {
- return true;
- } else if (obj == null) {
- return false;
- } else if (getClass() != obj.getClass()) {
- return false;
- } else {
- VariableDiceNode other = (VariableDiceNode) obj;
-
- if (variableName == null) {
- if (other.variableName != null) {
- return false;
- }
- } else if (!variableName.equals(other.variableName)) {
- return false;
- }
-
- return true;
- }
- }
-
- @Override
- public DiceASTType getType() {
- return DiceASTType.VARIABLE;
- }
-
- /**
- * Get the variable referenced by this AST node
- *
- * @return the variable referenced by this AST node
- */
- public String getVariable() {
- return variableName;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result
- + ((variableName == null) ? 0 : variableName.hashCode());
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see bjc.utils.dice.ast.IDiceASTNode#isOperator()
- */
- @Override
- public boolean isOperator() {
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return variableName;
- }
-} \ No newline at end of file
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/package-info.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/package-info.java
deleted file mode 100644
index f0f7366..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/package-info.java
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * Classes for nodes in the dice-lang AST
- *
- * @author ben
- *
- */
-package bjc.dicelang.ast.nodes; \ No newline at end of file