mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-04 09:58:30 -08:00
Add some comments.
This commit is contained in:
parent
67b95edd44
commit
cb98601ae5
|
@ -146,6 +146,11 @@ public class Abacus {
|
||||||
return tree.reduce(numberReducer);
|
return tree.reduce(numberReducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a number from a string.
|
||||||
|
* @param numberString the string to create the number from.
|
||||||
|
* @return the resulting number.
|
||||||
|
*/
|
||||||
public NumberInterface numberFromString(String numberString){
|
public NumberInterface numberFromString(String numberString){
|
||||||
Class<? extends NumberInterface> toInstantiate =
|
Class<? extends NumberInterface> toInstantiate =
|
||||||
pluginManager.numberFor(configuration.getNumberImplementation());
|
pluginManager.numberFor(configuration.getNumberImplementation());
|
||||||
|
|
|
@ -4,16 +4,40 @@ import org.nwapw.abacus.tree.TreeNode;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TreeBuilder class used to piece together a Tokenizer and
|
||||||
|
* Parser of the same kind. This is used to essentially avoid
|
||||||
|
* working with any parameters at all, and the generics
|
||||||
|
* in this class are used only to ensure the tokenizer and parser
|
||||||
|
* are of the same type.
|
||||||
|
* @param <T> the type of tokens created by the tokenizer and used by the parser.
|
||||||
|
*/
|
||||||
public class TreeBuilder<T> {
|
public class TreeBuilder<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tokenizer used to convert a string into tokens.
|
||||||
|
*/
|
||||||
private Tokenizer<T> tokenizer;
|
private Tokenizer<T> tokenizer;
|
||||||
|
/**
|
||||||
|
* The parser used to parse a list of tokens into a tree.
|
||||||
|
*/
|
||||||
private Parser<T> parser;
|
private Parser<T> parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Tree Builder with the given tokenizer and parser
|
||||||
|
* @param tokenizer the tokenizer to turn strings into tokens
|
||||||
|
* @param parser the parser to turn tokens into a tree
|
||||||
|
*/
|
||||||
public TreeBuilder(Tokenizer<T> tokenizer, Parser<T> parser){
|
public TreeBuilder(Tokenizer<T> tokenizer, Parser<T> parser){
|
||||||
this.tokenizer = tokenizer;
|
this.tokenizer = tokenizer;
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the given string into a tree.
|
||||||
|
* @param input the string to parse into a tree.
|
||||||
|
* @return the resulting tree.
|
||||||
|
*/
|
||||||
public TreeNode fromString(String input){
|
public TreeNode fromString(String input){
|
||||||
List<T> tokens = tokenizer.tokenizeString(input);
|
List<T> tokens = tokenizer.tokenizeString(input);
|
||||||
if(tokens == null) return null;
|
if(tokens == null) return null;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user