package evaluator
The evaluator
package is designed to simplify the process of parsing a string.
The work of parsing a string is reduced to just tokenizing an expression, that is, breaking it down into its
principal parts. The AbstractEvaluator
class will handle the rest.
The AbstractTokenizer
makes this even easier, though it is only applicable in some situations.
- Alphabetic
- By Inheritance
- evaluator
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
abstract
class
AbstractEvaluator
[R] extends Evaluator[R]
A skeletal implementation of the Evaluator class to avoid duplication of common logic.
A skeletal implementation of the Evaluator class to avoid duplication of common logic.
This class is applicable if, and only if, for each character it is unambiguous whether it is part of a word or special character. That is, every character can be either a special character, or part of a word, but not both. Furthermore, neither special characters not words can contain whitespace.
A 'special character' here is a standalone character that has a special meaning. Special characters cannot be part of values or words. For example,
+
would be a special character.A 'word' here is a meaningful string of characters that do not contain any whitespace or special characters. For example, the constant
pi
is a word, as are functions such assin
. Words cannot contain special characters or they could be mistaken for two words - the worda+b
would be split intoa
,+
, andb
.- R
The type that the string input should be evaluated to
- abstract class AbstractTokenizer [R] extends Tokenizer[R]
-
sealed
trait
Associativity
extends AnyRef
This represents the associativity of an operator.
This represents the associativity of an operator.
Operators can be either left associative or right associative. This indicated the order in which operators of the same precedence are evaluated in the absence of parentheses - from left to right or from right to left.
For example, the
/
operator is left associative, so2 / 2 / 2 = (2 / 2) / 2
However, the
^
operator is right associative, so2 ^ 2 ^ 2 = 2 ^ (2 ^ 2)
-
case class
EvaluationException
(message: String = "Syntax error", cause: Throwable = null) extends Exception with Product with Serializable
This is thrown by an Evaluator when it is parsing an expression with a syntax error.
This is thrown by an Evaluator when it is parsing an expression with a syntax error.
- message
The detailed message
- cause
The cause
-
abstract
class
Evaluator
[+R] extends AnyRef
An
Evaluator
is a string parser and evaluator.An
Evaluator
is a string parser and evaluator.This class is flexible, allowing a user to define their own syntax. An example use might be to parse maths expressions, such as
(1 + 2) ^ 3
.
- R
The type that the string input should be evaluated to
- See also
-
sealed
trait
Token
[R] extends AnyRef
Represents one of the base parts of an string expression
Represents one of the base parts of an string expression
- R
The type that the string represents
-
trait
Tokenizer
[R] extends AnyRef
This tokenizes a string, breaking it down into its principle parts.
This tokenizes a string, breaking it down into its principle parts. This may be useful when parsing a string when overriding the Evaluator trait, particularly its AbstractEvaluator.
- R
The type of token that the string should be evaluated to
Value Members
-
object
Associativity
Contains the instances of the associativity trait.
-
object
Token
Contains all the different types of tokens.
This is the documentation for the Evaluator project (see GitHub).
The main package net.totietje.evaluator. The net.totietje.complex package contains an example usage of this package, which may also be useful.