public class ASTNodeFactory extends Object implements IParserFactory
Modifier and Type | Field and Description |
---|---|
static ASTNodeFactory |
MMA_STYLE_FACTORY |
static int |
PLUS_PRECEDENCE |
static int |
POWER_PRECEDENCE |
static int |
TIMES_PRECEDENCE |
DEFAULT_OPERATOR_CHARACTERS
Constructor and Description |
---|
ASTNodeFactory()
Create a default ASTNode factory.
|
Modifier and Type | Method and Description |
---|---|
static void |
addOperator(Map<String,Operator> operatorMap,
Map<String,ArrayList<Operator>> operatorTokenStartSet,
String operatorStr,
String headStr,
Operator oper)
Adds the operator.
|
FunctionNode |
createAST(ASTNode headExpr)
Creates a new function with no arguments from the given header expression
.
|
ASTNode |
createDouble(String doubleString)
Create an double node from the given double value string.
|
FractionNode |
createFraction(IntegerNode numerator,
IntegerNode denominator)
Create a "fractional" number.
|
FunctionNode |
createFunction(SymbolNode head)
Creates a new function with head
head and 0 arguments. |
FunctionNode |
createFunction(SymbolNode head,
ASTNode arg0)
Creates a new function with head
head and 1 argument. |
FunctionNode |
createFunction(SymbolNode head,
ASTNode arg0,
ASTNode arg1)
Creates a new function with head
head and 2 arguments. |
static InfixOperator |
createInfixOperator(String operatorStr,
String headStr,
int precedence,
int grouping)
Creates a new ASTNode object.
|
IntegerNode |
createInteger(int intValue)
Create an integer node from the given value.
|
IntegerNode |
createInteger(String integerString,
int numberFormat)
Create an integer node from the given string.
|
PatternNode |
createPattern(SymbolNode patternName,
ASTNode check)
Create a pattern from the given symbol node.
|
static PostfixOperator |
createPostfixOperator(String operatorStr,
String headStr,
int precedence)
Creates a new ASTNode object.
|
static PrefixOperator |
createPrefixOperator(String operatorStr,
String headStr,
int precedence)
Creates a new ASTNode object.
|
StringNode |
createString(StringBuffer buffer)
Create a string node from the scanned double quoted string.
|
SymbolNode |
createSymbol(String symbolName)
Create a symbol from the scanned identifier string.
|
Operator |
get(String identifier)
Get the operator for a given identifier string like Times, Plus, Sin,...
|
Map<String,Operator> |
getIdentifier2OperatorMap()
Get identifier to operator map.
|
Map<String,ArrayList<Operator>> |
getOperator2ListMap()
Gets the operator 2 list map.
|
String |
getOperatorCharacters()
Gets the operator characters.
|
List<Operator> |
getOperatorList(String key)
Get the operator-list for a given operator-string.
|
boolean |
isValidIdentifier(String identifier)
Check if the identifier name is valid.
|
public static final int PLUS_PRECEDENCE
public static final int TIMES_PRECEDENCE
public static final int POWER_PRECEDENCE
public static final ASTNodeFactory MMA_STYLE_FACTORY
public static void addOperator(Map<String,Operator> operatorMap, Map<String,ArrayList<Operator>> operatorTokenStartSet, String operatorStr, String headStr, Operator oper)
operatorMap
- the operator mapoperatorTokenStartSet
- the operator token start setoperatorStr
- the operator strheadStr
- the head stroperatorMap
- the operator mapoperatorTokenStartSet
- the operator token start setoperatorStr
- the operator stroper
- the operpublic String getOperatorCharacters()
getOperatorCharacters
in interface IParserFactory
public Map<String,Operator> getIdentifier2OperatorMap()
getIdentifier2OperatorMap
in interface IParserFactory
public Operator get(String identifier)
get
in interface IParserFactory
identifier
- the identifierpublic Map<String,ArrayList<Operator>> getOperator2ListMap()
getOperator2ListMap
in interface IParserFactory
public List<Operator> getOperatorList(String key)
getOperatorList
in interface IParserFactory
key
- the operator stringpublic static InfixOperator createInfixOperator(String operatorStr, String headStr, int precedence, int grouping)
operatorStr
- the operator strheadStr
- the head strprecedence
- the precedencegrouping
- the groupingpublic static PrefixOperator createPrefixOperator(String operatorStr, String headStr, int precedence)
operatorStr
- the operator strheadStr
- the head strprecedence
- the precedencepublic static PostfixOperator createPostfixOperator(String operatorStr, String headStr, int precedence)
operatorStr
- the operator strheadStr
- the head strprecedence
- the precedencepublic ASTNode createDouble(String doubleString)
createDouble
in interface IParserFactory
doubleString
- the double stringpublic FunctionNode createFunction(SymbolNode head)
head
and 0 arguments. Creates a new ASTNode object.createFunction
in interface IParserFactory
head
- the headpublic FunctionNode createFunction(SymbolNode head, ASTNode arg0)
head
and 1 argument. Creates a new ASTNode object.createFunction
in interface IParserFactory
head
- the headarg0
- the arg 0public FunctionNode createFunction(SymbolNode head, ASTNode arg0, ASTNode arg1)
head
and 2 arguments. Creates a new ASTNode object.createFunction
in interface IParserFactory
head
- the headarg0
- the arg 0arg1
- the arg 1public FunctionNode createAST(ASTNode headExpr)
createAST
in interface IParserFactory
headExpr
- the head exprpublic IntegerNode createInteger(String integerString, int numberFormat)
createInteger
in interface IParserFactory
integerString
- the integer number represented as a StringnumberFormat
- the format of the number (usually 10)public IntegerNode createInteger(int intValue)
createInteger
in interface IParserFactory
intValue
- the integer number's valuepublic FractionNode createFraction(IntegerNode numerator, IntegerNode denominator)
createFraction
in interface IParserFactory
numerator
- numerator of the fractional numberdenominator
- denominator of the fractional numberpublic PatternNode createPattern(SymbolNode patternName, ASTNode check)
createPattern
in interface IParserFactory
patternName
- the pattern namecheck
- the checkpublic StringNode createString(StringBuffer buffer)
createString
in interface IParserFactory
buffer
- the bufferpublic SymbolNode createSymbol(String symbolName)
createSymbol
in interface IParserFactory
symbolName
- the symbol namepublic boolean isValidIdentifier(String identifier)
isValidIdentifier
in interface IParserFactory
identifier
- the currently parsed identifierfalse
if the identifier is not valid (in this case
the parser creates a SyntaxError exception); otherwise return
true
Copyright © 2017. All rights reserved.