|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.webcompmath.data.Parser
public class Parser
A Parser can take a string and compile it into an ExpressionProgram. MathObjects, such as variables and functions, can be registered with the Parser. This means that the Parser will recognize them in the strings that it parses. There are a few options that can be set to control certain aspects of the parsing. If a string does not have the correct syntax for an expression, then the Parser will throw a ParseError when it tries to parse that string. A Parser can have a parent. It inherits any MathObjects registered with its parent, but a MathObject registered with a Parser will hide any MathObject of the same name that is registered with its parent. Every parser recognizes the constants pi and e and the operators +, -, *, /, ^, and **. The ** operator is a synonym for ^, the exponentiation operator. Both unary and binary + and - are recognized. The exponentiation operator is right associative. The others are left associative.
Field Summary | |
---|---|
static int |
BOOLEANS
An option that can be set for this parser. |
static int |
BRACES
An option that can be set for this parser. |
static int |
BRACKETS
An option that can be set for this parser. |
static int |
CASE_SENSITIVE
An option that can be set for this parser. |
static int |
DEFAULT_OPTIONS
The default options set that is used for a newly created Parser, if none is specified in the Constructor. |
static int |
FACTORIAL
An option that can be set for this parser. |
static int |
NO_DIGITS_IN_IDENTIFIERS
An option that can be set for this parser. |
static int |
NO_UNDERSCORE_IN_IDENTIFIERS
An option that can be set for this parser. |
static int |
OPTIONAL_FUNCTIONS
An option that can be set for this parser. |
static int |
OPTIONAL_PARENS
An option that can be set for this parser. |
static int |
OPTIONAL_SPACES
An option that can be set for this parser. |
static int |
OPTIONAL_STARS
An that can be set for this parser. |
protected int |
options
The set of options that have been enabled for this parser. |
static int |
RATIONAL_EXPONENTS
An option that can be set for this parser. |
static int |
STANDARD_FUNCTIONS
An option that can be set for this parser. |
protected SymbolTable |
symbols
The symbol table that contains the MathObjects that have been registered with this parser. |
Constructor Summary | |
---|---|
Parser()
Construct a Parser with no parent and with the default options, BOOLEANS and STANDARD_FUNCTIONS. |
|
Parser(int options)
Create a Parser with the spedified option set and with no parent. |
|
Parser(Parser parent)
Create a Parser with the specified parent. |
|
Parser(Parser parent,
int options)
Create a Parser with the specified parent. |
Method Summary | |
---|---|
void |
add(MathObject sym)
Register the MathObject with the Parser, associating it with its name. |
void |
addOptions(int newOptions)
Add the options in the option set newOptions to this Parser's option set. |
MathObject |
get(java.lang.String name)
Get the MathObject that has been registered with the parser under the given name. |
protected int |
getOptions()
Gets the current options. |
ExpressionProgram |
parse(java.lang.String str)
Parse the string str and create the corresponding expression. |
boolean |
parseExpression(ParserContext context)
Called as part of the parsing process. |
boolean |
parseFactor(ParserContext context)
Called as part of the parsing process. |
ExpressionProgram |
parseLogical(java.lang.String str)
Parse the String, str, and create a corresponding logical-valued expression. |
boolean |
parseLogicalExpression(ParserContext context)
Called as part of the parsing process. |
boolean |
parseLogicalFactor(ParserContext context)
Called as part of the parsing process. |
boolean |
parseLogicalTerm(ParserContext context)
Called as part of the parsing process. |
boolean |
parsePrimary(ParserContext context)
Called as part of the parsing process. |
boolean |
parseRelation(ParserContext context)
Called as part of the parsing process. |
boolean |
parseTerm(ParserContext context)
Called as part of the parsing process. |
void |
remove(java.lang.String name)
Deregister the MathObject with the given name, if there is one registered with the Parser. |
void |
setVariable(Variable inVar)
added by PKHG 050415 to make visual building of GraphApplet1 possible |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int CASE_SENSITIVE
public static final int OPTIONAL_STARS
public static final int OPTIONAL_SPACES
public static final int BRACKETS
public static final int BRACES
public static final int BOOLEANS
public static final int FACTORIAL
public static final int NO_UNDERSCORE_IN_IDENTIFIERS
public static final int NO_DIGITS_IN_IDENTIFIERS
public static final int OPTIONAL_PARENS
public static final int STANDARD_FUNCTIONS
public static final int OPTIONAL_FUNCTIONS
public static final int RATIONAL_EXPONENTS
public static final int DEFAULT_OPTIONS
protected int options
protected SymbolTable symbols
Constructor Detail |
---|
public Parser()
public Parser(Parser parent)
parent
- the parent to use in creating a parserpublic Parser(int options)
options
- options to use in creating parserpublic Parser(Parser parent, int options)
parent
- parent of this Parser, possibly null.options
- additional options, in addition to ones inherited from parent.Method Detail |
---|
public void addOptions(int newOptions)
newOptions
- options to addprotected int getOptions()
public ExpressionProgram parse(java.lang.String str)
str
- String to parse.
public ExpressionProgram parseLogical(java.lang.String str)
str
- String to parse.
public MathObject get(java.lang.String name)
name
- name of the math object
public void add(MathObject sym)
sym
- mathobject to registerpublic void remove(java.lang.String name)
name
- MathObject to deregister.public boolean parseLogicalExpression(ParserContext context)
context
- the parser context to use
public boolean parseLogicalTerm(ParserContext context)
context
- the parser context to use
public boolean parseLogicalFactor(ParserContext context)
context
- the parser context to use
public boolean parseRelation(ParserContext context)
context
- parser context to use
public boolean parseExpression(ParserContext context)
context
- parser context to use
public boolean parseTerm(ParserContext context)
context
- parser context to use
public boolean parsePrimary(ParserContext context)
context
- parser context to use
public boolean parseFactor(ParserContext context)
context
- parser context to use
public void setVariable(Variable inVar)
inVar
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |