mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-23 07:50:09 -08:00
Implement the components of a new tree builder.
This commit is contained in:
parent
10c25fd478
commit
7b1b9aa01c
10
src/org/nwapw/abacus/parsing/Parser.java
Normal file
10
src/org/nwapw/abacus/parsing/Parser.java
Normal 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);
|
||||
}
|
9
src/org/nwapw/abacus/parsing/Tokenizer.java
Normal file
9
src/org/nwapw/abacus/parsing/Tokenizer.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package org.nwapw.abacus.parsing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Tokenizer<T> {
|
||||
|
||||
public List<T> tokenizeString(String string);
|
||||
|
||||
}
|
23
src/org/nwapw/abacus/parsing/TreeBuilder.java
Normal file
23
src/org/nwapw/abacus/parsing/TreeBuilder.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user