Binding Variables and Procedures

Aug 15, 2007 at 8:15 PM
Hi, i need to reimplement a software that is made in clarion language, this language allows dynamic expressions, and bind into the dynamic expressions variables and procedures, the mechanism is

BIND('VarA', VarA)
tells the compiler, when evaluating string, if you find the characters 'VarA' it means the offset of memory of the var VarA

Same with procedures so i can build special procedures like:

CalculateInterest(REAL amount), REAL

And use it in dynamic expressions like:

BIND('CalculateInterest', CalculateInterest)
BIND('VarAmount', VarAmount)

VarInterest = EVALUATE('CalculateInterest(VarAmount)')

Can i acomplish something similar with FLEE in C# ?

in all examples i see you use predefined attributes like

owner.a = 4;

Are the hard-coded ??
Can you do something like:

owner.AddField('A', 4);

instead? so we are not limited to hard-coded fields...

Thanks for your time.

Aug 16, 2007 at 4:48 PM

Hi,
ExpressionOwner is the symbol table, have static nature, and dynamic members not allows.

An idea is:

public class ExpressionOwner {

public Map<string,double> var;

}


ExpressionOwner owner = new ExpressionOwner();
owner.var.Add('A',5);

...

Expression expr = new Expression("var\"A\"+5", owner, options);
ExpressionEvaluator<double> eval = (ExpressionEvaluator<double>)expr.Evaluator;
double result = eval();

...
but Dinamyc Vars and List Expressions not allowed ...

Thanks,




Aug 17, 2007 at 3:26 AM
Hi,

I will see if I can implement this over the weekend. Internally, the solution will probably wind up being very similar to what jmptrader has described but you will be able to reference variables by just using their name. Binding method names will be more complicated since it will require a delegate or methodInfo.

Thanks,

Eugene
Aug 17, 2007 at 1:03 PM
Thank, but im still understandign this :-D

ExpressionOwner its a class of FLEE or its jus any Object ?

Can i use my own class as owner and i have available all my object properties ?

Also, in the options, can i add a import of any namespace of my own, and the use my own functions like you do with System.Math ?

what limitations this have or what rules i must follow?

Thanks


Aug 17, 2007 at 2:27 PM
>ExpressionOwner its a class of FLEE or its jus any Object ?
Flee dynamically creates a method based on the given expression. .NET requires that this method be attached to a class (or module). Once attached, the method acts as a static method on the type. I chose to call the class that I attach the method to the Expression Owner. It can be any object.

>Can i use my own class as owner and i have available all my object properties ?
Yes, the expression has access to all public/non-public fields, properties, and methods (static and instance) on the owner.

>Also, in the options, can i add a import of any namespace of my own, and the use my own functions like you do with System.Math ?
You can import a System.Type and then you can use its static methods in the expression without requiring any qualification (ie: "cos(a)"). You can import a namespace and then you can use to all types directly in the namespace by qualifying them with the type name (ie: "DateTime.Now"). You can also use any functions on the expression owner and any functions on its fields/properties ("myvar.tostring()").