summaryrefslogtreecommitdiff
path: root/dice-lang/src/main/java/bjc/dicelang/ast/nodes
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-04-10 20:10:36 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-04-10 20:10:36 -0400
commitbf726639e1bc70b30dc5e5ae2cf349a5bbdfb0ae (patch)
tree0ebe89df2fe7f2b1c6ff9564959191e3ede2e002 /dice-lang/src/main/java/bjc/dicelang/ast/nodes
parent90d1cc6c9f47f1b6f74fb57e07865795a46c23b8 (diff)
Moved things around for rewrite of AST mechanisms
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/IDiceASTNode.java23
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/LiteralDiceNode.java192
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/nodes/OperatorDiceNode.java92
-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.java6
6 files changed, 0 insertions, 441 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/IDiceASTNode.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/IDiceASTNode.java
deleted file mode 100644
index afa0bcd..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 {
- /**
- * Check if this node represents an operator or not
- *
- * @return Whether or not this node represents an operator
- */
- public boolean isOperator();
-
- /**
- * Get the type of AST node this node is
- *
- * @return The type of AST node this AST node is
- */
- public DiceASTType getType();
-} \ No newline at end of file
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/LiteralDiceNode.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/LiteralDiceNode.java
deleted file mode 100644
index 1a6d2bf..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/LiteralDiceNode.java
+++ /dev/null
@@ -1,192 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-import org.apache.commons.lang3.StringUtils;
-
-import bjc.dicelang.ComplexDice;
-import bjc.dicelang.CompoundDice;
-import bjc.dicelang.IDiceExpression;
-import bjc.dicelang.ScalarDie;
-import bjc.utils.data.Pair;
-import bjc.utils.parserutils.AST;
-
-/**
- * A AST node that represents a literal value
- *
- * @author ben
- *
- */
-public class LiteralDiceNode implements IDiceASTNode {
- private static boolean isValidInfixOperator(String dat, String op) {
- return StringUtils.countMatches(dat, op) == 1
- && !dat.equalsIgnoreCase(op) && !dat.startsWith(op);
- }
-
- /**
- * The value contained by this node
- */
- private String value;
-
- /**
- * Create a new node with the given value
- *
- * @param data
- * The value to be in this node
- */
- public LiteralDiceNode(String data) {
- this.value = data;
- }
-
- /**
- * Create a new node with the given value
- *
- * @param val
- * The value for this node
- */
- public LiteralDiceNode(int val) {
- this(Integer.toString(val));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- } else if (obj == null) {
- return false;
- } else if (getClass() != obj.getClass()) {
- return false;
- } else {
- LiteralDiceNode other = (LiteralDiceNode) obj;
-
- if (value == null) {
- if (other.value != null) {
- return false;
- }
- } else if (!value.equals(other.value)) {
- return false;
- }
-
- return true;
- }
- }
-
- /**
- * Get the data stored in this AST node
- *
- * @return the data stored in this AST node
- */
- public String getData() {
- return value;
- }
-
- @Override
- public DiceASTType getType() {
- return DiceASTType.LITERAL;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((value == null) ? 0 : value.hashCode());
- return result;
- }
-
- @Override
- public boolean isOperator() {
- return false;
- }
-
- /**
- * Parse this node into an expression
- *
- * @return The node in expression form
- */
- public IDiceExpression toExpression() {
- String literalData = this.getData();
-
- if (LiteralDiceNode.isValidInfixOperator(literalData, "c")) {
- String[] strangs = literalData.split("c");
-
- return new CompoundDice(strangs);
- } else if (LiteralDiceNode.isValidInfixOperator(literalData,
- "d")) {
- /*
- * Handle dice groups
- */
- return ComplexDice.fromString(literalData);
- } else {
- try {
- return new ScalarDie(Integer.parseInt(literalData));
- } catch (NumberFormatException nfex) {
- UnsupportedOperationException usex = new UnsupportedOperationException(
- "Found malformed leaf token " + this);
-
- usex.initCause(nfex);
-
- throw usex;
- }
- }
- }
-
- /**
- * Parse this node into an expression
- *
- * @return The node as a pair of a sample value and the AST it
- * represents
- */
- public Pair<Integer, AST<IDiceASTNode>> toParseValue() {
- AST<IDiceASTNode> returnedAST = new AST<>(this);
-
- IDiceExpression expression = toExpression();
-
- return new Pair<>(expression.roll(), returnedAST);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return value;
- }
-
- /**
- * Check if this node represents a constant value
- *
- * @return Whether or not this node represents a constant value
- */
- public boolean isConstant() {
- try {
- Integer.parseInt(value);
- return true;
- } catch (@SuppressWarnings("unused") NumberFormatException nfex) {
- // We don't care about details
- return false;
- }
- }
-
- /**
- * Return the constant value this node represents
- *
- * @return The constant value of this node
- *
- * @throws NumberFormatException
- * if you call this on a node that doesn't represent a
- * constant value
- */
- public int toConstant() {
- return Integer.parseInt(value);
- }
-} \ No newline at end of file
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 2820cfb..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/OperatorDiceNode.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package bjc.dicelang.ast.nodes;
-
-// The following classes need to be changed upon addition of a new operator
-// 1. DiceASTExpression
-// 2. DiceASTFlattener
-// 3. DiceASTParser
-/**
- * A node that represents an operator
- *
- * @author ben
- *
- */
-public enum OperatorDiceNode implements IDiceASTNode {
- /**
- * Represents adding two nodes
- */
- ADD,
- /**
- * Represents assigning one node to another
- */
- ASSIGN,
- /**
- * Representings combining two node values together
- */
- COMPOUND,
- /**
- * Represents dividing two nodes
- */
- DIVIDE,
- /**
- * Represents using one node a variable number of times
- */
- GROUP,
- /**
- * Represents multiplying two nodes
- */
- MULTIPLY,
- /**
- * Represents subtracting two nodes
- */
- SUBTRACT,
- /**
- * Represents executing one statement in the context of the other
- */
- LET;
-
- /**
- * 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":
- return GROUP;
- case "c":
- return COMPOUND;
- case "->":
- return LET;
- default:
- throw new IllegalArgumentException(
- s + " is not a valid operator node");
- }
- }
-
- @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 29fd483..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 variable reference
- *
- * @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 97f1990..0000000
--- a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/package-info.java
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * This package contains the various Node types in the Dice AST
- * @author ben
- *
- */
-package bjc.dicelang.ast.nodes; \ No newline at end of file