diff options
| author | student <student@localhost> | 2018-03-05 16:48:49 -0500 |
|---|---|---|
| committer | student <student@localhost> | 2018-03-05 16:48:49 -0500 |
| commit | ccd92f9b09dfbf1f16f50787ef2510e038dccf06 (patch) | |
| tree | 707bf9635c9a9609175dd9025b0d0b04c9cb97f2 | |
| parent | 40f7102be6f0871bcae97458a2ab8044db33f886 (diff) | |
Update
6 files changed, 82 insertions, 4 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 diff --git a/JPratt/src/main/java/bjc/pratt/commands/MetaInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/MetaInitialCommand.java index 9f14f36..d209177 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/MetaInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/MetaInitialCommand.java @@ -6,8 +6,22 @@ import bjc.pratt.ParserContext; * A 'meta-command' that yields the actual command to use.
*
* @author bjculkin
+ *
+ * @param <K>
+ * The key type of the context.
+ * @param <V>
+ * The value type of the context.
+ * @param <C>
+ * The storage type of the context.
*
*/
public interface MetaInitialCommand<K, V, C> {
+ /**
+ * Get the command to use.
+ *
+ * @param ctx
+ * The current parser context.
+ * @return The command to use.
+ */
InitialCommand<K, V, C> getCommand(ParserContext<K, V, C> ctx);
}
diff --git a/JPratt/src/main/java/bjc/pratt/commands/MetaNonInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/MetaNonInitialCommand.java index 9d09eef..956dcec 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/MetaNonInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/MetaNonInitialCommand.java @@ -8,14 +8,21 @@ import bjc.pratt.ParserContext; * @author bjculkin * * @param <K> - * The token key type. + * The token key type. * * @param <V> - * The token value type. + * The token value type. * * @param <C> - * The parser state type. + * The parser state type. */ public interface MetaNonInitialCommand<K, V, C> { + /** + * Get the command to use. + * + * @param ctx + * The context to use. + * @return The command to use. + */ NonInitialCommand<K, V, C> getCommand(ParserContext<K, V, C> ctx); } |
