From 7a510ceb37780a7d0da37117a5cfce23c2919257 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 10 Apr 2017 22:55:22 -0400 Subject: More work on parse blocks --- .../bjc/pratt/commands/BlockNonInitialCommand.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 JPratt/src/main/java/bjc/pratt/commands/BlockNonInitialCommand.java (limited to 'JPratt/src/main/java/bjc/pratt/commands/BlockNonInitialCommand.java') diff --git a/JPratt/src/main/java/bjc/pratt/commands/BlockNonInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/BlockNonInitialCommand.java new file mode 100644 index 0000000..9a5ffc9 --- /dev/null +++ b/JPratt/src/main/java/bjc/pratt/commands/BlockNonInitialCommand.java @@ -0,0 +1,74 @@ +package bjc.pratt.commands; + +import bjc.pratt.NonInitialCommand; +import bjc.pratt.ParseBlock; +import bjc.pratt.ParserContext; +import bjc.pratt.Token; +import bjc.utils.data.ITree; +import bjc.utils.data.Tree; +import bjc.utils.parserutils.ParserException; + +/** + * A non-initial command that delegates all of the work to a {@link ParseBlock} + * + * @author bjculkin + * + * @param + * The token key type. + * + * @param + * The token value type. + * + * @param + * The parser state type. + */ +public class BlockNonInitialCommand extends NonInitialCommand { + private ParseBlock innr; + + private int lftBind; + private int nxtBind; + + private Token trm; + + /** + * Create a new non-initial command that delegates to a parse block. + * + * @param inner + * The parse block to delegate to. + * + * @param leftBind + * The left binding power (precedence). + * + * @param rightBind + * The right binding power (associativity control). + * + * @param term + * The token to use as the node in the AST. + */ + public BlockNonInitialCommand(ParseBlock inner, int leftBind, int rightBind, Token term) { + innr = inner; + + lftBind = leftBind; + nxtBind = rightBind; + + trm = term; + } + + @Override + public ITree> denote(ITree> operand, Token operator, ParserContext ctx) + throws ParserException { + ITree> expression = innr.parse(ctx); + + return new Tree<>(trm, expression); + } + + @Override + public int leftBinding() { + return lftBind; + } + + @Override + public int nextBinding() { + return nxtBind; + } +} \ No newline at end of file -- cgit v1.2.3