1 using Mercury.Exceptions;
2 using Mercury.Nucleus.Trees;
5 using System.Collections.Generic;
9 namespace Mercury.Interpreting
22 public delegate T
RecursiveEval<T>(Tree<Symbol> tree, InterpreterContext<T> context)
46 public abstract class InterpreterAction<T>
53 if (
string.IsNullOrWhiteSpace(Name))
56 if ((Arity.Item1 < 0) || (Arity.Item2 < 0) || (Arity.Item1 > Arity.Item2))
59 if ((ArgumentTypes.Length == 0) && ((Arity.Item1 != 0) || (Arity.Item2 != 0)))
62 for (
int ix = 0; ix < ArgumentTypes.Length; ++ix)
64 throw new InvalidActionException(this.ToString(),
"argument type {0}, {1} is not a valid type", ix, ArgumentTypes[ix].ToString());
95 bool allowswild =
true)
97 if (name == null)
throw new ArgumentNullException(
"name");
98 if (arity == null)
throw new ArgumentNullException(
"arity");
99 if (argtypes == null)
throw new ArgumentNullException(
"argtypes");
103 ArgumentTypes = argtypes;
104 ReturnType = ArgumentType.TValue;
105 AllowsWildcard = allowswild;
113 public string Name {
get;
internal set; }
116 public Tuple<int, int> Arity {
get;
internal set; }
132 public bool AllowsWildcard {
get;
internal set; }
157 public abstract class InterpreterAction<T, U> : InterpreterAction<T>
172 : base(name, arity, argtypes, allowswild)
174 ReturnType = Defaults.TypeToArgType<T, U>();
175 var rtp = Defaults.TypeToArgType<T, T>();
177 if ((ReturnType & rtp) != ArgumentType.None)
195 #region [ IInterpreterAction ]
199 {
return Evaluate(arguments, eval, context); }
214 public abstract class GenericAction<T> : InterpreterAction<T>
228 : base(name, arity, argtypes, allowswild)
229 { ReturnType = ArgumentType.None; }
InterpreterAction(string name, Tuple< int, int > arity, ArgumentType[] argtypes, bool allowswild=true)
Initializes a new instance of the InterpreterAction{T,U} class. See Mercury.Interpreting.InterpreterAction{T} for better explanation.
delegate T RecursiveEval< T >(Tree< Symbol > tree, InterpreterContext< T > context)
Delegate type for recursive evaluation (interpretation)
An exception representing a problem with Mercury.Interpreting.InterpreterAction{T} class...
override object Invoke(Argument[] arguments, RecursiveEval< T > eval, InterpreterContext< T > context)
Evaluates the arguments. It is guaranteed to have a valid number of arguments (specified by Arity) a...
ArgumentType
Defines argument types using in the Mercury library
InterpreterAction(string name, Tuple< int, int > arity, ArgumentType[] argtypes, bool allowswild=true)
Initializes a new instance of the InterpreterAction{T} class. The target application can inherit from...
GenericAction(string name, Tuple< int, int > arity, ArgumentType[] argtypes, bool allowswild=true)
Initializes a GenericAction{T} instance.
Represents an argument passed to the Mercury.Interpreting.InterpreterAction{T}, the actual parameter ...
Interpreter Context class. Some languages may use it to override it and remember data when parse tree...