1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-11-17 16:09:32 -08:00

Implement the components of a new tree builder.

This commit is contained in:
Danila Fedorin 2017-07-29 21:02:41 -07:00
parent 10c25fd478
commit 7b1b9aa01c
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,10 @@
package org.nwapw.abacus.parsing;
import org.nwapw.abacus.tree.TreeNode;
import java.util.List;
public interface Parser<T> {
public TreeNode constructTree(List<T> tokens);
}

View File

@ -0,0 +1,9 @@
package org.nwapw.abacus.parsing;
import java.util.List;
public interface Tokenizer<T> {
public List<T> tokenizeString(String string);
}

View File

@ -0,0 +1,23 @@
package org.nwapw.abacus.parsing;
import org.nwapw.abacus.tree.TreeNode;
import java.util.List;
public class TreeBuilder<T> {
private Tokenizer<T> tokenizer;
private Parser<T> parser;
public TreeBuilder(Tokenizer<T> tokenizer, Parser<T> parser){
this.tokenizer = tokenizer;
this.parser = parser;
}
public TreeNode fromString(String input){
List<T> tokens = tokenizer.tokenizeString(input);
if(tokens == null) return null;
return parser.constructTree(tokens);
}
}