- JavaDoc

# Jep Java

- Introduction
- Basic Usage
- Variables
- Data types
- Operators
- Functions
- Custom Functions
- BigDecimal
- Modules
- Printing
- FAQ
- Migration
- Version History

# Advanced Features

- Manipulating Expressions
- Components
- Configurable Parser
- Serialization
- Threads
- Localization
- Grammar
- Other advanced features
- Use of Design Patterns in Jep

# Component Architecture

With Jep 3.0, a new component architecture was introduced. It allows pluggable components, giving tremendous flexibility for customizing Jep. A total of 9 components are employed, as shown below.

- Parser
- Evaluator
- VariableTable
- FunctionTable
- OperatorTable
- VariableFactory
- NumberFactory
- NodeFactory
- PrintVisitor

For each of the components you can either use a built-in implementation, or you can create your own implementation.

The roles of these components are:

- Parser - parses expressions.
- Evaluator - evaluates expressions.
- VariableTable - stores the set of variables.
- FunctionTable - stores the sets of known functions.
- OperatorTable - stores the set of operators.
- VariableFactory - creates new variables.
- NumberFactory - creates objects representing numbers (typically Double) from string representations.
- NodeFactory - creates nodes in the parse tree.
- PrintVisitor - prints equations.

A set of components can be bundled together in a ComponentSet and the Jep(ComponentSet cs) constructor used to create a Jep instance with a given set. Individual components can be set using jep.setComponent(JepComponent comp).

## Built-in components

Jep comes with many components built-in. When creating a `Jep` instance using the default constructor, the `StandardComponents` set is loaded. The standard components include the StandardParser and the FastEvaluator. In addition to those, the ConfigurableParser and the RealEvaluator are also available. The following listing gives an overview of the components available in Jep 3.

StandardComponents (the default component set)
com.singularsys.jep.standard.StandardComponents

- StandardParser (JavaCC generated parser)
- FastEvaluator
- VariableFactory
- DoubleNumberFactory
- NodeFactory
- StandardVariableTable
- StandardFunctionTable
- StandardOperatorTable

BigDecimalComponents (see Big Decimals)

- BigDecFunctionTable (initializes a set a functions that can handle BigDecimals)
- BigDecNumberFactory (creates BigDecimal numbers)
- BigDecOperatorTable (initializes BigDecimal operators)

Other components

- RealEvaluator (allows fast evaluation of `double` arithmetic and functions)
- RealComponentSet (functions never return complex numbers and the variable i is not defined) includes:
  - RealFunctionTable (functions don't return complex values)
  - RealVariableTable (has constants `pi, e, true, false` but not the complex number `i`.)
- StandardEvaluator (the pre-v3.3 evaluator, kept for compatibility)
- PostfixEvaluator (traverses trees without using recursion, for very large expressions)
- CaseInsensitiveFunctionTable (a function table which is case-insensitive)
- CaseInsensitiveVariableTable (a variable table which is case-insensitive)
- Configurable Parser (for customizable syntax)
- NullParser (a do-nothing parser)
- NullWrappedFunctionTable A function table where every function treats null like SQL's NULL.
- BitwiseOperatorTable An operator table which adds bitwise operators `a|b` `a>>b` etc.
- JavaOperatorTable A operator table which adds bitwise operators and the full set of Java operators `++x`, `x?y:z` etc.
- LineNumberingNodeFactory A node factory which stores line number information.
- LineNumberingShuntingYard.LineNumberGrammarParserFactory Part of the configurable parser which adds line number info.

## Custom components

The architecture also allows for new custom components can be loaded. These should implement the appropriate interface or extend the appropriate class. Two methods are common to all components (see JepComponent):

- `void init(Jep jep)` this is called after the Jep instance is constructed or when a component is changed and is used to inform all active components about the configuration. A do nothing method is typical.
- `public JepComponent getLightWeightInstance()` in multi threaded environments with multiple Jep instances some components can be shared, but other need a separate instance per thread. This method returns an appropriate instance, which can be `this`, `null` or a new instance. See Serialization for details.