From 98cdf435d4974f4cca8f7b4eb4026da2c88cbc4c Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 26 Mar 2017 11:30:43 -0400 Subject: Update --- .../pratt/commands/AbstractInitialCommand.java | 21 ++++++++++--- .../parserutils/pratt/commands/BinaryCommand.java | 28 +++++++++++++++--- .../parserutils/pratt/commands/ChainCommand.java | 34 +++++++++++++++++++--- .../pratt/commands/ConstantCommand.java | 23 +++++++++++++-- .../pratt/commands/DefaultNonInitialCommand.java | 2 -- .../pratt/commands/InitialInterleaveCommand.java | 29 ------------------ .../pratt/commands/InterleaveSpecifier.java | 30 ------------------- 7 files changed, 92 insertions(+), 75 deletions(-) delete mode 100644 BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InitialInterleaveCommand.java delete mode 100644 BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt') diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/AbstractInitialCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/AbstractInitialCommand.java index b263422..3c3a89b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/AbstractInitialCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/AbstractInitialCommand.java @@ -6,14 +6,27 @@ import bjc.utils.parserutils.pratt.InitialCommand; import bjc.utils.parserutils.pratt.ParserContext; import bjc.utils.parserutils.pratt.Token; +/** + * Abstract base for initial commands. + * + * @author bjculkin + * + * @param + * The key type of the tokens. + * + * @param + * The value type of the tokens. + * + * @param + * The state type of the parser. + */ public abstract class AbstractInitialCommand implements InitialCommand { @Override - public ITree> denote(Token operator, ParserContext ctx) - throws ParserException { + public ITree> denote(Token operator, ParserContext ctx) throws ParserException { return intNullDenotation(operator, ctx); } - protected abstract ITree> intNullDenotation(Token operator, - ParserContext ctx) throws ParserException; + protected abstract ITree> intNullDenotation(Token operator, ParserContext ctx) + throws ParserException; } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/BinaryCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/BinaryCommand.java index bf6786b..781309c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/BinaryCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/BinaryCommand.java @@ -6,16 +6,36 @@ import bjc.utils.parserutils.ParserException; import bjc.utils.parserutils.pratt.ParserContext; import bjc.utils.parserutils.pratt.Token; +/** + * A binary operator. + * + * @author bjculkin + * + * @param + * The key type of the tokens. + * + * @param + * The value type of the tokens. + * + * @param + * The state type of the parser. + */ public abstract class BinaryCommand extends BinaryPostCommand { - public BinaryCommand(int leftPower) { - super(leftPower); + /** + * Create a new binary operator with the specified precedence. + * + * @param precedence + * The precedence of the operator. + */ + public BinaryCommand(int precedence) { + super(precedence); } protected abstract int rightBinding(); @Override - public ITree> denote(ITree> operand, Token operator, - ParserContext ctx) throws ParserException { + public ITree> denote(ITree> operand, Token operator, ParserContext ctx) + throws ParserException { ITree> opr = ctx.parse.parseExpression(rightBinding(), ctx.tokens, ctx.state, false); return new Tree<>(operator, operand, opr); diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ChainCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ChainCommand.java index aa85f75..1324586 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ChainCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ChainCommand.java @@ -8,21 +8,47 @@ import bjc.utils.parserutils.pratt.Token; import java.util.Set; +/** + * Create a new chained operator. + * + * @author bjculkin + * + * @param + * The key type of the tokens. + * + * @param + * The value type of the tokens. + * + * @param + * The state type of the parser. + */ public class ChainCommand extends BinaryPostCommand { private Set chainWith; private Token chain; - public ChainCommand(int leftPower, Set chainSet, Token chainMarker) { - super(leftPower); + /** + * Create a new chained operator. + * + * @param precedence + * The precedence of this operator. + * + * @param chainSet + * The operators to chain with. + * + * @param chainMarker + * The token to use as the node in the AST. + */ + public ChainCommand(int precedence, Set chainSet, Token chainMarker) { + super(precedence); chainWith = chainSet; chain = chainMarker; } @Override - public ITree> denote(ITree> operand, Token operator, - ParserContext ctx) throws ParserException { + public ITree> denote(ITree> operand, Token operator, ParserContext ctx) + throws ParserException { ITree> tree = ctx.parse.parseExpression(1 + leftBinding(), ctx.tokens, ctx.state, false); ITree> res = new Tree<>(operator, operand, tree); diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ConstantCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ConstantCommand.java index 2308cc7..10ff184 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ConstantCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ConstantCommand.java @@ -6,16 +6,35 @@ import bjc.utils.parserutils.pratt.InitialCommand; import bjc.utils.parserutils.pratt.ParserContext; import bjc.utils.parserutils.pratt.Token; +/** + * A command that represents a specific tree. + * + * @author bjculkin + * + * @param + * The key type of the tokens. + * + * @param + * The value type of the tokens. + * + * @param + * The state type of the parser. + */ public class ConstantCommand implements InitialCommand { private ITree> val; + /** + * Create a new constant. + * + * @param con + * The tree this constant represents. + */ public ConstantCommand(ITree> con) { val = con; } @Override - public ITree> denote(Token operator, ParserContext ctx) - throws ParserException { + public ITree> denote(Token operator, ParserContext ctx) throws ParserException { return val; } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/DefaultNonInitialCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/DefaultNonInitialCommand.java index 8c500a9..887dd25 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/DefaultNonInitialCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/DefaultNonInitialCommand.java @@ -20,7 +20,6 @@ import bjc.utils.parserutils.pratt.Token; * The state type of the parser. */ public class DefaultNonInitialCommand extends NonInitialCommand { - @Override public ITree> denote(ITree> operand, Token operator, ParserContext ctx) { throw new UnsupportedOperationException("Default command has no left denotation"); @@ -30,5 +29,4 @@ public class DefaultNonInitialCommand extends NonInitialCommand - * The token key type. - * - * @param - * The token value type. - * - * @param - * The parser state type. - */ -public class InitialInterleaveCommand extends AbstractInitialCommand { - @Override - protected ITree> intNullDenotation(Token operator, ParserContext ctx) - throws ParserException { - return null; - } - -} diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java deleted file mode 100644 index fa2c592..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java +++ /dev/null @@ -1,30 +0,0 @@ -package bjc.utils.parserutils.pratt.commands; - -/** - * The specifier for what to do for each element of a command. - * - * @author EVE - * - */ -public class InterleaveSpecifier { - /** - * The type of this specifier. - * - * @author EVE - * - */ - public static enum Type { - /** - * Parse an expression with the given priority. - */ - EXPRESSION, - /** - * Parse a statement with the given priority. - */ - STATEMENT, - /** - * Expect a token of a certain type to be present. - */ - EXPECT, LITERAL; - } -} \ No newline at end of file -- cgit v1.2.3