mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-16 07:33:09 -08:00
24 lines
534 B
Java
24 lines
534 B
Java
|
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);
|
||
|
}
|
||
|
|
||
|
}
|