diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-04-10 22:55:22 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-04-10 22:55:22 -0400 |
| commit | 7a510ceb37780a7d0da37117a5cfce23c2919257 (patch) | |
| tree | e5f7a796cc6555cdcc5f09d969408f80c79b10e8 /JPratt/src/main/java/bjc/pratt/commands/BlockNonInitialCommand.java | |
| parent | 56f07e9a3aaa873fe385d224f088f048dbafa8f7 (diff) | |
More work on parse blocks
Diffstat (limited to 'JPratt/src/main/java/bjc/pratt/commands/BlockNonInitialCommand.java')
| -rw-r--r-- | JPratt/src/main/java/bjc/pratt/commands/BlockNonInitialCommand.java | 74 |
1 files changed, 74 insertions, 0 deletions
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 <K> + * The token key type. + * + * @param <V> + * The token value type. + * + * @param <C> + * The parser state type. + */ +public class BlockNonInitialCommand<K, V, C> extends NonInitialCommand<K, V, C> { + private ParseBlock<K, V, C> innr; + + private int lftBind; + private int nxtBind; + + private Token<K, V> 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<K, V, C> inner, int leftBind, int rightBind, Token<K, V> term) { + innr = inner; + + lftBind = leftBind; + nxtBind = rightBind; + + trm = term; + } + + @Override + public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx) + throws ParserException { + ITree<Token<K, V>> 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 |
