|
Orbital library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object orbital.moon.logic.MathExpressionSyntax
public class MathExpressionSyntax
This class implements an expression syntax for mathematical expressions. Those expressions currently get parsed as a composition of functions. An alternative implementation would already evaluate the expression instead of explicitly constructing a representation as a composition of functions.
Field Summary | |
---|---|
static java.lang.String |
usage
|
Constructor Summary | |
---|---|
MathExpressionSyntax()
|
Method Summary | |
---|---|
Expression.Composite |
compose(Expression compositor,
Expression[] arguments)
Create a compound expression representation with a composition operation. |
Signature |
coreSignature()
Get the core signature which is supported by the language of this expression syntax. |
Expression |
createAtomic(Symbol symbol)
Create an atomic expression representation of a non-compound sign. |
Expression |
createExpression(java.lang.String expression)
Create a term representation by parsing a (compound) expression.. |
Arithmetic |
createMathExpression(java.lang.String expression)
Parses an expression and queries its arithmetic object. |
Arithmetic |
getValueOf(Expression x)
Get the arithmetic object represented by an expression. |
static void |
main(java.lang.String[] arg)
tool-main |
Signature |
scanSignature(java.lang.String expression)
Scan for the signature Σ of all syntactic symbols in an expression. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String usage
Constructor Detail |
---|
public MathExpressionSyntax()
Method Detail |
---|
public static void main(java.lang.String[] arg) throws java.lang.Exception
java.lang.Exception
public Expression createExpression(java.lang.String expression) throws ParseException
In fact, parsing expressions is only possible with a concrete syntax. So implementations of this method are encouraged to define and parse a standard notation which can often be close to the default notation of the abstract syntax.
.
createExpression
in interface ExpressionSyntax
expression
- the compound expression to parse.
A string of ""
denotes the empty expression.
However note that the empty expression may not be accepted in some term algebras.
Those parsers rejecting the empty expression are then inclined to throw a ParseException,
instead.
ParseException
- when the expression is syntactically malformed.
Either due to a lexical or grammatical error.createMathExpression(String)
public Arithmetic createMathExpression(java.lang.String expression) throws ParseException
ParseException
createExpression(String)
,
getValueOf(Expression)
public Signature coreSignature()
ExpressionSyntax
The core "signature" contains the logical signs that inherently belong to this term algebra and are not subject to interpretation. Logical signs are logical constants like true, false, and logical operators like ¬, ∧, ∨, →, ∀, ∃. The latter are also called logical junctors.
Note that some authors do not count the core "signature" as part of the proper signature Σ but would rather call it "meta"-signature.
coreSignature
in interface ExpressionSyntax
Logic.coreInterpretation()
public Signature scanSignature(java.lang.String expression) throws ParseException
ExpressionSyntax
However, note that this method does not necessarily perform rich type querying. Especially for user-defined functions with an arbitrary argument-type structure, it is generally recommended to construct the relevant signature entries explicitly.
scanSignature
in interface ExpressionSyntax
expression
- the expression that should be scanned for symbol names.
ParseException
- (optional) when the expression is syntactically malformed.
Either due to a lexical or grammatical error.
(optional behaviour for performance reasons).
Will not throw ParseExceptions if createExpression would not either.ExpressionSyntax.coreSignature()
,
"Factory Method"public Expression createAtomic(Symbol symbol)
ExpressionBuilder
Atomic symbols are either elemental atoms, strings or numbers. ☡ In contrast, a logical formula that is not compound of something (on the level of logical junctors) like "P(x,y)" is sometimes called atom.
createAtomic
in interface ExpressionBuilder
symbol
- the symbol whose atomic expression representation to create.
public Expression.Composite compose(Expression compositor, Expression[] arguments) throws ParseException
ExpressionBuilder
Signature.get(String,Object[])
may be useful for determining the right functor symbol
for a composition in case of an atomic
compositor.
☡ Be aware that this method does a composition (in the sense of semiotics) of signs/expressions, but not usually a composition (in the sense of mathematics) of functions. Mathematically speaking, the composition that this method performs would usually be called application instead of composition. Although composition (in the sense of mathematics) and application are correlated, they have different types at first sight
Yet together withλ
-abstraction,
composition can be expressed in terms of application (as the definition above shows).
And in conjunction with the (selective) identification of type
void→σ' with σ'
application can also be expressed per composition.
compose
in interface ExpressionBuilder
compositor
- the expression that is used for composing the arguments.arguments
- the arguments a
passed to the combining operation.
compositor(a[0],…,a[a.length-1])
ParseException
- if the composition expression is syntactically malformed.
Either due to a lexical or grammatical error (also due to wrong type of arguments).public Arithmetic getValueOf(Expression x)
|
Orbital library 1.3.0: 11 Apr 2009 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |