summaryrefslogtreecommitdiff
path: root/JPratt/src/examples/java
diff options
context:
space:
mode:
authorstudent <student@localhost>2018-03-05 16:48:49 -0500
committerstudent <student@localhost>2018-03-05 16:48:49 -0500
commitccd92f9b09dfbf1f16f50787ef2510e038dccf06 (patch)
tree707bf9635c9a9609175dd9025b0d0b04c9cb97f2 /JPratt/src/examples/java
parent40f7102be6f0871bcae97458a2ab8044db33f886 (diff)
Update
Diffstat (limited to 'JPratt/src/examples/java')
-rw-r--r--JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java27
-rw-r--r--JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java13
-rw-r--r--JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangEvaluator.java13
-rw-r--r--JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangResult.java6
4 files changed, 58 insertions, 1 deletions
diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java
index 4fa84b8..3ee1887 100644
--- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java
+++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java
@@ -5,13 +5,33 @@ import bjc.pratt.examples.lang.evaluator.LangResult;
import bjc.pratt.tokens.Token;
import bjc.utils.data.TopDownTransformResult;
+/**
+ * Represents the AST for the language.
+ *
+ * @author student
+ *
+ */
public interface LangAST {
+ /**
+ * Evaluate the AST.
+ *
+ * @return The evaluated AST
+ */
LangResult toResult();
+ /**
+ * Create an AST from a token.
+ *
+ * @param token
+ * The token to create the AST from
+ * @return The new AST
+ * @throws EvaluatorException
+ * If something goes wrong.
+ */
static LangAST fromToken(Token<String, String> token) throws EvaluatorException {
String key = token.getKey();
- switch(key) {
+ switch (key) {
case "(literal)":
return LiteralAST.fromToken(token);
default:
@@ -21,6 +41,11 @@ public interface LangAST {
}
}
+ /**
+ * Get the way an AST node should be evaluated.
+ *
+ * @return The way to evaluate the AST node.
+ */
default TopDownTransformResult getEvaluationStrategy() {
return TopDownTransformResult.PUSHDOWN;
}
diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java
index d9a7ad2..85289d9 100644
--- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java
+++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java
@@ -3,7 +3,20 @@ package bjc.pratt.examples.lang.ast;
import bjc.pratt.tokens.Token;
import bjc.utils.data.TopDownTransformResult;
+/**
+ * AST node for a literal.
+ *
+ * @author student
+ *
+ */
public interface LiteralAST extends LangAST {
+ /**
+ * Create a new literal AST
+ *
+ * @param tok
+ * The token to build from.
+ * @return The AST for the token.
+ */
static LiteralAST fromToken(Token<String, String> tok) {
return null;
}
diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangEvaluator.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangEvaluator.java
index 7ce1939..3ebab16 100644
--- a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangEvaluator.java
+++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangEvaluator.java
@@ -3,7 +3,20 @@ package bjc.pratt.examples.lang.evaluator;
import bjc.pratt.examples.lang.ast.LangAST;
import bjc.utils.data.ITree;
+/**
+ * Evaluate an AST.
+ *
+ * @author student
+ *
+ */
public class LangEvaluator {
+ /**
+ * Evaluate an AST
+ *
+ * @param ast
+ * The AST to evaluate
+ * @return The result of evaluation.
+ */
public LangResult evaluate(ITree<LangAST> ast) {
ITree<LangAST> evaluatedTree = ast.topDownTransform(LangAST::getEvaluationStrategy, this::evaluateNode);
diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangResult.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangResult.java
index 06b3471..35c5bb3 100644
--- a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangResult.java
+++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangResult.java
@@ -1,5 +1,11 @@
package bjc.pratt.examples.lang.evaluator;
+/**
+ * The result of evaluating an AST.
+ *
+ * @author student
+ *
+ */
public class LangResult {
} \ No newline at end of file