From 7b1b9aa01ce2ff709a584b72f9c0009295bb0f57 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 29 Jul 2017 21:02:41 -0700 Subject: [PATCH] Implement the components of a new tree builder. --- src/org/nwapw/abacus/parsing/Parser.java | 10 ++++++++ src/org/nwapw/abacus/parsing/Tokenizer.java | 9 ++++++++ src/org/nwapw/abacus/parsing/TreeBuilder.java | 23 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/org/nwapw/abacus/parsing/Parser.java create mode 100644 src/org/nwapw/abacus/parsing/Tokenizer.java create mode 100644 src/org/nwapw/abacus/parsing/TreeBuilder.java diff --git a/src/org/nwapw/abacus/parsing/Parser.java b/src/org/nwapw/abacus/parsing/Parser.java new file mode 100644 index 0000000..0103a7d --- /dev/null +++ b/src/org/nwapw/abacus/parsing/Parser.java @@ -0,0 +1,10 @@ +package org.nwapw.abacus.parsing; + +import org.nwapw.abacus.tree.TreeNode; + +import java.util.List; + +public interface Parser { + + public TreeNode constructTree(List tokens); +} diff --git a/src/org/nwapw/abacus/parsing/Tokenizer.java b/src/org/nwapw/abacus/parsing/Tokenizer.java new file mode 100644 index 0000000..4baef10 --- /dev/null +++ b/src/org/nwapw/abacus/parsing/Tokenizer.java @@ -0,0 +1,9 @@ +package org.nwapw.abacus.parsing; + +import java.util.List; + +public interface Tokenizer { + + public List tokenizeString(String string); + +} diff --git a/src/org/nwapw/abacus/parsing/TreeBuilder.java b/src/org/nwapw/abacus/parsing/TreeBuilder.java new file mode 100644 index 0000000..57de6ed --- /dev/null +++ b/src/org/nwapw/abacus/parsing/TreeBuilder.java @@ -0,0 +1,23 @@ +package org.nwapw.abacus.parsing; + +import org.nwapw.abacus.tree.TreeNode; + +import java.util.List; + +public class TreeBuilder { + + private Tokenizer tokenizer; + private Parser parser; + + public TreeBuilder(Tokenizer tokenizer, Parser parser){ + this.tokenizer = tokenizer; + this.parser = parser; + } + + public TreeNode fromString(String input){ + List tokens = tokenizer.tokenizeString(input); + if(tokens == null) return null; + return parser.constructTree(tokens); + } + +}