|
Mercury library
1.0
Translation of CFG grammars into an object model (Bachelor's thesis).
|
Contains basic actions for interpretation.
Type specifiers of actions are defined as follows:
More...
Static Public Member Functions | |
| static IReadOnlyList < InterpreterAction< T > > | GetAllActions () |
| Provides basic Mercury actions More... | |
| static IReadOnlyDictionary < string, string > | GetAliases () |
| Returns aliases for basic actions. It contains the following aliases: More... | |
| static InterpreterAction< T > | CreateTracer (string name, TextWriter writer) |
| Creates custom trace action with stream, useful for logging. More... | |
Static Public Attributes | |
| static readonly InterpreterAction< T > | ParseInteger |
Converts a string representation of an integer.ParseInteger :: String -> Integer More... | |
| static readonly InterpreterAction< T > | ParseReal |
Converts a string representation of a decimal number.ParseReal :: String -> Real More... | |
| static readonly InterpreterAction< T > | ParseBoolean |
Converts a string representation of a boolean.ParseBoolean :: String -> Boolean More... | |
| static readonly InterpreterAction< T > | Round = new ConvertAction<T, double, int>("Round", x => Convert.ToInt32(Math.Round(x))) |
Rounds a real number.Round :: Real -> Integer More... | |
| static readonly InterpreterAction< T > | Ceiling = new ConvertAction<T, double, int>("Ceiling", x => Convert.ToInt32(Math.Ceiling(x))) |
Returns a ceiling of a real number.Ceiling :: Real -> Integer More... | |
| static readonly InterpreterAction< T > | Floor = new ConvertAction<T, double, int>("Floor", x => Convert.ToInt32(Math.Floor(x))) |
Returns a floor of a real number.Floor :: Real -> Integer More... | |
| static readonly InterpreterAction< T > | ToReal = new ConvertAction<T, int, double>("ToReal", x => Convert.ToDouble(x)) |
Converts an integer value to decimal.ToReal :: Integer -> Real More... | |
| static readonly InterpreterAction< T > | String = new ConvertAction<T, object, string>("String", x => x.ToString()) |
Call ToString() method on its argument.String :: Any -> String More... | |
| static readonly InterpreterAction< T > | Add = new ArithmeticAction<T>("Add", (x, y) => x + y) |
Sum of the arguments.Add[a = Integer|Real] :: a -> a -> ... -> a More... | |
| static readonly InterpreterAction< T > | Sub = new ArithmeticAction<T>("Sub", (x, y) => x - y) |
Subtracts the arguments.Sub[a = Integer|Real] :: a -> a -> ... -> a More... | |
| static readonly InterpreterAction< T > | Mul = new ArithmeticAction<T>("Mul", (x, y) => x * y) |
Multiplies the arguments.Mul[a = Integer|Real] :: a -> a -> ... -> a More... | |
| static readonly InterpreterAction< T > | Div = new ArithmeticAction<T>("Div", (x, y) => x / y) |
Divides the values.Div[a = Integer|Real] :: a -> a -> ... -> a More... | |
| static readonly InterpreterAction< T > | Pow = new ArithmeticAction<T>("Pow", (x, y) => Math.Pow(x, y)) |
Exponentiates the values.Pow[a = Integer|Real] :: a -> a -> ... -> a More... | |
| static readonly InterpreterAction< T > | FDiv = new OperationAction<T, double, double>("FDiv", (x, y) => x / y) |
Floating point division.FDiv :: Real -> Real -> Real More... | |
| static readonly InterpreterAction< T > | Mod = new OperationAction<T, int, int>("Mod", (x, y) => x % y) |
Modulo.Mod :: Integer -> Integer -> Integer More... | |
| static readonly InterpreterAction< T > | IsNull = new ConvertAction<T, object, bool>("IsNull", x => x == null, ArgumentType.Null) |
Indicates whether the object is null.IsNull :: Any -> Boolean More... | |
| static readonly InterpreterAction< T > | And = new FoldingAction<T, bool, bool>("And", 2, (x, y) => x && y, true) |
Logical multiplication.And :: Boolean -> Boolean -> ... -> Boolean More... | |
| static readonly InterpreterAction< T > | Or = new FoldingAction<T, bool, bool>("Or", 2, (x, y) => x && y, false) |
Logical addition.Or :: Boolean -> Boolean -> ... -> Boolean More... | |
| static readonly InterpreterAction< T > | Not = new ConvertAction<T, bool, bool>("Not", x => !x) |
Logical negation.Not :: Boolean -> Boolean More... | |
| static readonly InterpreterAction< T > | Xor = new OperationAction<T, bool, bool>("Xor", (x, y) => x ^ y) |
Exclusive disjunction.Xor :: Boolean -> Boolean -> Boolean More... | |
| static readonly InterpreterAction< T > | Eq = new OperationAction<T, object, bool>("Eq", (x, y) => (x != null) && x.Equals(y), ArgumentType.Null) |
Indicates whether provided objects are equal. If any of arguments is null, the result is always false.Eq :: Any -> Any -> Boolean More... | |
| static readonly InterpreterAction< T > | Neq = new OperationAction<T, object, bool>("Neq", (x, y) => (x == null) || !x.Equals(y), ArgumentType.Null) |
Complement of Eq.Neq :: Any -> Any -> Boolean More... | |
| static readonly InterpreterAction< T > | Gr = new OperationAction<T, double, bool>("Gr", (x, y) => x > y) |
Comparison "Greater than".Gr :: Real -> Real -> Boolean More... | |
| static readonly InterpreterAction< T > | Ls = new OperationAction<T, double, bool>("Ls", (x, y) => x < y) |
Comparison "Less than".Ls :: Real -> Real -> Boolean More... | |
| static readonly InterpreterAction< T > | Geq = new OperationAction<T, double, bool>("Geq", (x, y) => x >= y) |
Comparison "Greater than or equal to".Geq :: Real -> Real -> Boolean More... | |
| static readonly InterpreterAction< T > | Leq = new OperationAction<T, double, bool>("Leq", (x, y) => x <= y) |
Comparison "Less than or equal to".Leq :: Real -> Real -> Boolean More... | |
| static readonly InterpreterAction< T > | Empty = new ConstantAction<T, string>("Empty", "") |
Returns an empty string.Empty :: String More... | |
| static readonly InterpreterAction< T > | Join = new JoinAction<T>() |
Converts all arguments to strings and joins them with a given separator.Join :: String -> [Any...] -> String More... | |
| static readonly InterpreterAction< T > | Concat = new ConcatAction<T>() |
Converts all arguments to strings and concatenates them.Concat :: [Any...] -> String More... | |
| static readonly InterpreterAction< T > | Flatten = new FlattenAction<T>() |
Converts a tree into its string representation. An optional argument specifies the depth.Flatten :: Tree -> [Integer] -> String More... | |
| static readonly InterpreterAction< T > | Name = new ConvertAction<T, Symbol, string>("Name", x => x.Name) |
Returns the name of the given symbol.Name :: Symbol -> String More... | |
| static readonly InterpreterAction< T > | Symbol = new ConvertAction<T, Tree<Symbol>, Symbol>("Symbol", x => x.Value) |
Returns the root symbol of the given tree.Symbol :: Tree -> Symbol More... | |
| static readonly InterpreterAction< T > | Depth = new ConvertAction<T, Tree<Symbol>, int>("Depth", x => x.Depth) |
Returns the depth of the given tree.Depth :: Tree -> Integer More... | |
| static readonly InterpreterAction< T > | Leaves = new ConvertAction<T, Tree<Symbol>, int>("Leaves", x => x.LeavesCount) |
Returns the count of leaves of the given tree.Leaves :: Tree -> Integer More... | |
| static readonly InterpreterAction< T > | SubTree = new SubTreeAction<T>() |
Returns a child of a given tree at index specified as the second parameter. If no such child exists, the action returns null.SubTree :: Tree -> Integer -> Tree More... | |
| static readonly InterpreterAction< T > | Preterminal |
Returns a string value of a preterminal rule (of the form A -> b where b is the terminal. If the tree was not generated by a preterminal rule, returns null.Preterminal :: Tree -> String More... | |
| static readonly InterpreterAction< T > | If = new IfAction<T>() |
Condition. The semantics of (if c0 a0 c1 a1 ... e) is if (c0) then a1; else if (c1) then a1; ... else e;. All values and conditions are evaluated lazily.Moreover, types of a_ must be equal otherwise the type inference would fail.If[a = Any] :: [Boolean,a...] -> a -> a More... | |
| static readonly InterpreterAction< T > | Select = new SelectAction<T>() |
Selection. The semantics of (select i c0 c1 ... cn def) is if (0 <= i <= n) then ci; else def;. All values are evaluated lazily.Moreover, types of c_ must be equal otherwise the type inference would fail.Select[a = Any] :: Integer -> [a...] -> a -> a More... | |
| static readonly InterpreterAction< T > | Case = new CaseAction<T>() |
Case. The semantics of (case x c0 v0 c1 v1 ... def) isswitch (x) { case c0: v0; break; case c1: v1; break; ... default: def; }.Moreover, types of c_ and x must be equal, as well as types of v_.Case[v = Any, e = Any] :: v -> [v,e...] -> e -> e More... | |
| static readonly InterpreterAction< T > | Eval = new EvaluateAction<T>() |
Recursively evaluates the given tree.Eval :: Tree -> TValue More... | |
| static readonly InterpreterAction< T > | Simple = new SimpleAction<T>() |
Evaluates the subtree of a given tree provided that it is the only subtree; otherwise returns null.Simple :: Tree -> TValue More... | |
| static readonly InterpreterAction< T > | Fail = new FailAction<T>() |
Returns null.Fail :: Any More... | |
| static readonly InterpreterAction< T > | Try = new TryAction<T>() |
Try action. The semantics of (try e1 e2) is try { e1; } catch (Mercury.Exceptions.ErrorActionException) { e2; }.If the second argument is not specified, it will behave like (try e1 (fail)). Moreover, the types of e1 and e2 must be equal.Try[a = Any] :: a -> a -> a More... | |
| static readonly InterpreterAction< T > | Error = new ConvertAction<T, string, object>("Error", x => { throw new ErrorActionException(x); }) |
Throws an instance of Mercury.Exceptions.ErrorActionException with the specified text.Error :: String -> Any More... | |
| static readonly InterpreterAction< T > | Identity = new IdentityAction<T>() |
Returns the same value.Identity[a = Any] :: a -> a More... | |
| static readonly InterpreterAction< T > | Let = new LetAction<T>() |
| Saves the value in the current context. The semantics of (Let x v0 y v1 ... act) is let (x = v0; y = v1; ...) in (act);.The return type is same as the type of act.Let[a = Any] :: [String,Any...] -> a -> a More... | |
| static readonly InterpreterAction< T > | Var = new VarAction<T>() |
Retrieves the value stored by Let, but only in the same context. The function also performs runtime type check; if the value stored does not exist or match the type required, it will throw an exception.Var :: String -> Any More... | |
| static readonly InterpreterAction< T > | ArgsCount = new ArgsCountAction<T>() |
Returns the number of arguments. Useful to determine number of values captured by a Mercury.Interpreting.Wildcard.ArgsCount :: [Any...] -> Integer More... | |
| static readonly InterpreterAction< T > | Trace = new TraceAction<T>() |
Logs an event to the entry tree.Trace[a = Any] -> a -> String -> [Any...] -> a More... | |
Contains basic actions for interpretation.
Type specifiers of actions are defined as follows:
f :: type defines an action f of type type.f[a = X] :: type defines an action f of type type, where a gets replaced by X and is always of the same type.Syntax of action types is as follows:
a -> b -> c is a function that takes two arguments of type a and b and returns an argument of type c.[X] is an optional argument of type X.[X...] is an arbitrary number of arguments of type X.[X,Y...] is an arbitrary number of arguments in the form of X -> Y -> X -> Y etc.... arbitrary number of same arguments as previous, i.e. Integer -> ... is at least one Integer.Note that if f :: a -> [b] -> [c] -> d, the third argument of type c cannot be specified without the second argument of type b.
| T | Interpreter return type. |
| T | : | class |
Definition at line 39 of file BasicActions.cs.
|
static |
Creates custom trace action with stream, useful for logging.
| name | The name of the action |
| writer | The output writer |
Definition at line 352 of file BasicActions.cs.
|
static |
Returns aliases for basic actions.
It contains the following aliases:
+ Add - Sub * Mul / Div
// FDiv % Mod ** Pow
@ String ++ Concat # Var
& And | Or ^ Xor ! Not
== Eq /= Neq
> Gt < Lt >= Geq <= Leq
$ Eval id Identity
Definition at line 332 of file BasicActions.cs.
|
static |
Provides basic Mercury actions
| T | Output type parameter |
Definition at line 304 of file BasicActions.cs.
|
static |
Sum of the arguments.
Add[a = Integer|Real] :: a -> a -> ... -> a
Definition at line 96 of file BasicActions.cs.
|
static |
Logical multiplication.
And :: Boolean -> Boolean -> ... -> Boolean
Definition at line 123 of file BasicActions.cs.
|
static |
Returns the number of arguments. Useful to determine number of values captured by a Mercury.Interpreting.Wildcard.
ArgsCount :: [Any...] -> Integer
Definition at line 296 of file BasicActions.cs.
|
static |
Case. The semantics of (case x c0 v0 c1 v1 ... def) is
switch (x) { case c0: v0; break; case c1: v1; break; ... default: def; }.
Moreover, types of c_ and x must be equal, as well as types of v_.
Case[v = Any, e = Any] :: v -> [v,e...] -> e -> e
Definition at line 238 of file BasicActions.cs.
|
static |
Returns a ceiling of a real number.
Ceiling :: Real -> Integer
Definition at line 81 of file BasicActions.cs.
|
static |
Converts all arguments to strings and concatenates them.
Concat :: [Any...] -> String
Definition at line 168 of file BasicActions.cs.
|
static |
Returns the depth of the given tree.
Depth :: Tree -> Integer
Definition at line 186 of file BasicActions.cs.
|
static |
Divides the values.
Div[a = Integer|Real] :: a -> a -> ... -> a
Definition at line 105 of file BasicActions.cs.
|
static |
Returns an empty string.
Empty :: String
Definition at line 159 of file BasicActions.cs.
|
static |
Indicates whether provided objects are equal. If any of arguments is null, the result is always false.
Eq :: Any -> Any -> Boolean
Definition at line 138 of file BasicActions.cs.
|
static |
Throws an instance of Mercury.Exceptions.ErrorActionException with the specified text.
Error :: String -> Any
Definition at line 267 of file BasicActions.cs.
|
static |
Recursively evaluates the given tree.
Eval :: Tree -> TValue
Definition at line 241 of file BasicActions.cs.
|
static |
Returns null.
Fail :: Any
Definition at line 251 of file BasicActions.cs.
|
static |
Floating point division.
FDiv :: Real -> Real -> Real
Definition at line 111 of file BasicActions.cs.
|
static |
Converts a tree into its string representation. An optional argument specifies the depth.
Flatten :: Tree -> [Integer] -> String
Definition at line 174 of file BasicActions.cs.
|
static |
Returns a floor of a real number.
Floor :: Real -> Integer
Definition at line 84 of file BasicActions.cs.
|
static |
Comparison "Greater than or equal to".
Geq :: Real -> Real -> Boolean
Definition at line 150 of file BasicActions.cs.
|
static |
Comparison "Greater than".
Gr :: Real -> Real -> Boolean
Definition at line 144 of file BasicActions.cs.
|
static |
Returns the same value.
Identity[a = Any] :: a -> a
Definition at line 273 of file BasicActions.cs.
|
static |
Condition. The semantics of (if c0 a0 c1 a1 ... e) is if (c0) then a1; else if (c1) then a1; ... else e;. All values and conditions are evaluated lazily.
Moreover, types of a_ must be equal otherwise the type inference would fail.
If[a = Any] :: [Boolean,a...] -> a -> a
Definition at line 221 of file BasicActions.cs.
|
static |
Indicates whether the object is null.
IsNull :: Any -> Boolean
Definition at line 120 of file BasicActions.cs.
|
static |
Converts all arguments to strings and joins them with a given separator.
Join :: String -> [Any...] -> String
Definition at line 165 of file BasicActions.cs.
|
static |
Returns the count of leaves of the given tree.
Leaves :: Tree -> Integer
Definition at line 189 of file BasicActions.cs.
|
static |
Comparison "Less than or equal to".
Leq :: Real -> Real -> Boolean
Definition at line 153 of file BasicActions.cs.
|
static |
Saves the value in the current context.
The semantics of (Let x v0 y v1 ... act) is let (x = v0; y = v1; ...) in (act);.
The return type is same as the type of act.
Let[a = Any] :: [String,Any...] -> a -> a
Definition at line 282 of file BasicActions.cs.
|
static |
Comparison "Less than".
Ls :: Real -> Real -> Boolean
Definition at line 147 of file BasicActions.cs.
|
static |
Modulo.
Mod :: Integer -> Integer -> Integer
Definition at line 114 of file BasicActions.cs.
|
static |
Multiplies the arguments.
Mul[a = Integer|Real] :: a -> a -> ... -> a
Definition at line 102 of file BasicActions.cs.
|
static |
Returns the name of the given symbol.
Name :: Symbol -> String
Definition at line 180 of file BasicActions.cs.
|
static |
Complement of Eq.
Neq :: Any -> Any -> Boolean
Definition at line 141 of file BasicActions.cs.
|
static |
Logical negation.
Not :: Boolean -> Boolean
Definition at line 129 of file BasicActions.cs.
|
static |
Logical addition.
Or :: Boolean -> Boolean -> ... -> Boolean
Definition at line 126 of file BasicActions.cs.
|
static |
Converts a string representation of a boolean.
ParseBoolean :: String -> Boolean
Definition at line 71 of file BasicActions.cs.
|
static |
Converts a string representation of an integer.
ParseInteger :: String -> Integer
Definition at line 55 of file BasicActions.cs.
|
static |
Converts a string representation of a decimal number.
ParseReal :: String -> Real
Definition at line 63 of file BasicActions.cs.
|
static |
Exponentiates the values.
Pow[a = Integer|Real] :: a -> a -> ... -> a
Definition at line 108 of file BasicActions.cs.
|
static |
Returns a string value of a preterminal rule (of the form A -> b where b is the terminal. If the tree was not generated by a preterminal rule, returns null.
Preterminal :: Tree -> String
Definition at line 204 of file BasicActions.cs.
|
static |
Rounds a real number.
Round :: Real -> Integer
Definition at line 78 of file BasicActions.cs.
|
static |
Selection. The semantics of (select i c0 c1 ... cn def) is if (0 <= i <= n) then ci; else def;. All values are evaluated lazily.
Moreover, types of c_ must be equal otherwise the type inference would fail.
Select[a = Any] :: Integer -> [a...] -> a -> a
Definition at line 230 of file BasicActions.cs.
|
static |
Evaluates the subtree of a given tree provided that it is the only subtree; otherwise returns null.
Simple :: Tree -> TValue
Definition at line 248 of file BasicActions.cs.
|
static |
Call ToString() method on its argument.
String :: Any -> String
Definition at line 90 of file BasicActions.cs.
|
static |
Subtracts the arguments.
Sub[a = Integer|Real] :: a -> a -> ... -> a
Definition at line 99 of file BasicActions.cs.
|
static |
Returns a child of a given tree at index specified as the second parameter. If no such child exists, the action returns null.
SubTree :: Tree -> Integer -> Tree
Definition at line 196 of file BasicActions.cs.
|
static |
Returns the root symbol of the given tree.
Symbol :: Tree -> Symbol
Definition at line 183 of file BasicActions.cs.
|
static |
Converts an integer value to decimal.
ToReal :: Integer -> Real
Definition at line 87 of file BasicActions.cs.
|
static |
Logs an event to the entry tree.
Trace[a = Any] -> a -> String -> [Any...] -> a
Definition at line 299 of file BasicActions.cs.
|
static |
Try action. The semantics of (try e1 e2) is try { e1; } catch (Mercury.Exceptions.ErrorActionException) { e2; }.
If the second argument is not specified, it will behave like (try e1 (fail)). Moreover, the types of e1 and e2 must be equal.
Try[a = Any] :: a -> a -> a
Definition at line 260 of file BasicActions.cs.
|
static |
Retrieves the value stored by Let, but only in the same context. The function also performs runtime type check; if the value stored does not exist or match the type required, it will throw an exception.
Var :: String -> Any
Definition at line 290 of file BasicActions.cs.
|
static |
Exclusive disjunction.
Xor :: Boolean -> Boolean -> Boolean
Definition at line 132 of file BasicActions.cs.
1.8.7