Quantcast
Channel: Fast Lightweight Expression Evaluator
Viewing all 96 articles
Browse latest View live

New Post: DateTimeFormat property - Documentation Error

$
0
0
In the "Literals" section of the "Language Reference" page here:

http://flee.codeplex.com/wikipage?title=LanguageReference&referringTitle=Home#Literals

The description of the DateTime literal contains the following:

Use the ExpressionOptions.DateTimeFormat property to control the format.

After finding that the above property doesn't actually exist I dug through the code and found that the docs should have read:

Use the ParserOptions.DateTimeFormat property to control the format.

Thanks.

Commented Issue: Needs support for Extension Methods [10784]

$
0
0
With .NET 3.0 and up, .NET has method extensions. With this a method can be added onto an existing class (like an Int32). I want the extended methods to be accessible to the FLEE expression elements. The following example illustrates:
// An extension method for an int that determines how many numbers compose the integer if it was represented as a string.
static class IntExtension
{
public static int Length(this int i)
{
if (i <= 0) throw new ArgumentOutOfRangeException();
 
return (int)Math.Floor(Math.Log10(i)) + 1;
}
}
 
// Test for it.
// 3.Length() == 1
// 462.Length() == 3
 
Also see: http://www.extensionmethod.net/ for more examples of extension methods.
Comments: ** Comment from web user: zit35501 **

Hi,

I needed that feature also in my project, if someone wants it I have put my version to github: https://github.com/ThomasZitzler/flee

Seems to work.

I do not really check if the first paramter of the static method is really marked with the "this" keyword. I just enhanced the checks so that FLEE also accepts static methods with the current context object as first parameter (all thos have to be registered to the context!).

IL generation is actually same as for member calls.

New Post: Compilation Error - using non-static members

$
0
0
Hi,

I'm trying to use Flee to evaluate expressions from within Ninjatrader, a C# based trading platform.

I have a basic test working using the examples with an expressionowner.

My class is defined -
    public class ExpressionOwner 
    {
        public int a;

        public int myFunc(int i)
        {
            return(i);
        }
        public double getClose() {
            return Close[0];
        }
    }
The compilation error (referring to the line : return Close[0]) is -

Cannot access a non-static member of outer type 'NinjaTrader.Indicator.IndicatorBase' via nested type 'NinjaTrader.Indicator.FleeTest.ExpressionOwner'

I know I haven't provided a lot of detail here, particularly about Ninjatrader, but can anyone offer some suggestions? I'd be happy to provide more detail if anyone can help,

Thanks

Created Unassigned: OutOfMemoryException in ExpressionContext() [17600]

$
0
0
My C# application accesses FLEE from multiple simultaneous threads. For some reason, calling the default ExpressionContext constructor occasionally throws an OutOfMemoryException.

The first time I saw this problem, one thread was inside ExpressionContext.Compile and the faulting thread was inside the ExpressionContext constructor. Ok, so I figured that something in the constructor isn't thread-safe, so I put a lock around the constructor and Compile references (to prevent multiple threads from trying to execute those routines simultaneously). That reduced the probability of getting this exception, but did not eliminate it.

Now, looking at the stack traces of the 2 threads that are running when one thread throws this exception, I see that the exception is thrown from within the ExpressionContext default constructor, but the other thread is not in any FLEE code at all. FWIW, both threads have constructed and kept references to many hundreds of ExpressionContext objects.

Has anyone seen anything like this in their own use of FLEE?

(I've finally gotten to the point with this issue that I'm going to download the source code and debug the darned thing.)

Created Unassigned: EmitLiteral in Identifier.vb [17638]

$
0
0
Hello,

if you have an expression accessing a value type field member and using the result in a further expression element which requires an address you run into an unhandled exception within the IL code, e.g.

_Int32.MaxValue.ToString( )_

MaxValue is a constant field of a value type and the ToString( ) will cause the exception in the IL code.

_1.ToString( )_

doesn't run into that problem, since the IL code generation is done in a different way (no field member).

How to fix that?
Change Identifier.vb in the following way

1) add a new parameter _nextRequiresAddress As Boolean_ to _Sub EmitLiteral_ like

_Sub EmitLiteral(ByVal fi As System.Reflection.FieldInfo, ByVal ilg As FleeILGenerator, ByVal services As IServiceProvider, ByVal nextRequiresAddress As Boolean)_

2) after code line _elem.Emit(ilg, services)_ in _Sub EmitLiteral_ add the following code

_If nextRequiresAddress = True Then
EmitValueTypeLoadAddress(ilg, t)
End If_

3) change the _EmitFieldLoad Sub_ where the _EmitLiteral Sub_ is called like

_EmitLiteral(fi, ilg, services, Me.NextRequiresAddress)_

Many thanks to the author of Flee for this excellent library!
best regards grabul

Created Unassigned: Logical operation gives expressionCompile Exception [17684]

$
0
0
I have a formula : E or (A And (B Or C Or D))
And I pass boolean values to all parameters
But I get a expressionCompile exception and an indication that a double and a boolean cannot be evaluated.

{"AndOrElement: Operation 'Or' is not defined for types 'Double' and 'Boolean'"}
TypeMismatch

at Ciloci.Flee.ExpressionElement.ThrowCompileException(String messageKey, CompileExceptionReason reason, Object[] arguments)
at Ciloci.Flee.BinaryExpressionElement.ThrowOperandTypeMismatch(Object operation, Type leftType, Type rightType)
at Ciloci.Flee.BinaryExpressionElement.ValidateInternal(Object op)
at Ciloci.Flee.BinaryExpressionElement.Configure(ExpressionElement leftChild, ExpressionElement rightChild, Object op)
at Ciloci.Flee.BinaryExpressionElement.CreateElement(IList childValues, Type elementType)
at Ciloci.Flee.FleeExpressionAnalyzer.AddBinaryOp(Production node, Type elementType)
at Ciloci.Flee.FleeExpressionAnalyzer.ExitOrExpression(Production node)
at Ciloci.Flee.ExpressionAnalyzer.Exit(Node node)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.Parser.ExitNode(Node node)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParseAlternative(ProductionPatternAlternative alt)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParsePattern(ProductionPattern pattern)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParseElement(Production node, ProductionPatternElement elem)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParseAlternative(ProductionPatternAlternative alt)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParsePattern(ProductionPattern pattern)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParseElement(Production node, ProductionPatternElement elem)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParseAlternative(ProductionPatternAlternative alt)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParsePattern(ProductionPattern pattern)
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParseStart()
at Ciloci.Flee.PerCederberg.Grammatica.Runtime.Parser.Parse()
at Ciloci.Flee.ExpressionContext.DoParse()
at Ciloci.Flee.ExpressionContext.Parse(String expression, IServiceProvider services)
at Ciloci.Flee.Expression`1.Compile(String expression, ExpressionOptions options)
at Ciloci.Flee.Expression`1..ctor(String expression, ExpressionContext context, Boolean isGeneric)
at Ciloci.Flee.ExpressionContext.CompileGeneric[TResultType](String expression)
at ICeTechControlLibrary.Converters.BoolExpressionConverter.Convert(Object[] values, Type targetType, Object parameter, CultureInfo culture) in c:\Users\stuyckp\Documents\Visual Studio 2013\Projects\WPF\ICeTechControlLibrary\ICeTechControlLibrary\Converters\ExpressionConverter.cs:line 27
at System.Windows.Data.MultiBindingExpression.TransferValue()
at System.Windows.Data.MultiBindingExpression.Transfer()
at System.Windows.Data.MultiBindingExpression.UpdateTarget(Boolean includeInnerBindings)
at System.Windows.Data.MultiBindingExpression.AttachToContext(Boolean lastChance)
at System.Windows.Data.MultiBindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Run(Object arg)
at MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e)
at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

New Post: Available functions

$
0
0
Hi,

Do you have a full list of the functions available to the parser? The list in the documentation and the list on the codeplex page are missing quite a few: sin, cos, tan, log and so on. I've managed to guess quite a few but i can imagine there are others I can't guess. Would be very helpful to have a full list.

Many thanks.

Tim

New Post: Available functions


Created Unassigned: Turkish localization causes syntax errors [17730]

$
0
0
Due to the culture sensitive comparisons in the lexer setting a thread's CurrentCulture to tr-TR causes syntax errors when using capital letter I's in identifiers.

For example the expression "THIS" (without quotes) causes:
SyntaxError: Unexpected character: I
Line: 1, Column: 3

While the expression "this" works as intended.

I've provided a patch that replaces ToLower with ToLowerInvariant, which does not have this problem. It does not affect strings in any way as the results from ToLower aren't kept anywhere, the lexer only passes around indexes into the expression string.

Created Unassigned: Certain [17731]

$
0
0
Certain expressions containing a long condition in an IF statement give an exception in BranchManager:
```
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.get_Item(Int32 index)
at Ciloci.Flee.BranchManager.IsLongBranch(FleeILGenerator ilg, Label target) in D:\Projects\Flee\Flee-0.9.26.0\src\Lib\InternalTypes\BranchManager.vb:line 112
at Ciloci.Flee.ConditionalElement.EmitConditional(FleeILGenerator ilg, IServiceProvider services, BranchManager bm) in D:\Projects\Flee\Flee-0.9.26.0\src\Lib\ExpressionElements\Conditional.vb:line 84
at Ciloci.Flee.ConditionalElement.Emit(FleeILGenerator ilg, IServiceProvider services) in D:\Projects\Flee\Flee-0.9.26.0\src\Lib\ExpressionElements\Conditional.vb:line 70
at Ciloci.Flee.RootExpressionElement.Emit(FleeILGenerator ilg, IServiceProvider services) in D:\Projects\Flee\Flee-0.9.26.0\src\Lib\ExpressionElements\Root.vb:line 37
at Ciloci.Flee.Expression`1.Compile(String expression, ExpressionOptions options) in D:\Projects\Flee\Flee-0.9.26.0\src\Lib\InternalTypes\Expression.vb:line 96
at Ciloci.Flee.Expression`1..ctor(String expression, ExpressionContext context, Boolean isGeneric) in D:\Projects\Flee\Flee-0.9.26.0\src\Lib\InternalTypes\Expression.vb:line 58
at Ciloci.Flee.ExpressionContext.CompileDynamic(String expression) in D:\Projects\Flee\Flee-0.9.26.0\src\Lib\PublicTypes\ExpressionContext.vb:line 186
at FleeTest.Program.CompileExpression(Object expressionOwner, String expression, Dictionary`2 variables) in D:\Projects\Test\FleeTest\FleeTest\Program.cs:line 43
at FleeTest.Program.Evaluate[T](Object expressionOwner, String expression, Boolean defaultIfNull, Dictionary`2 variables) in D:\Projects\Test\FleeTest\FleeTest\Program.cs:line 63
at FleeTest.Program.RunExpression(Program t, String expression, Dictionary`2 customExpressions) in D:\Projects\Test\FleeTest\FleeTest\Program.cs:line 180
```
This error was generated from the expression:
```
if(\"1\" in ( \"1\"; \"2\"; \"3\"; \"4\"; \"5\"; \"6\"; \"7\"; \"8\"; \"9\"; \"10\"; \"11\"; \"12\"; \"13\"; \"14\"; \"15\"; \"16\"; \"17\"; \"18\"; \"19\"; \"20\" ); \"Test\"; null)
```
A bit convoluted but we have seen these errors in production with real expressions.

The exception seems to be related to Flee being unable to figure out one of the endpoints at the time it tries to decide if we want a long or short branch. I've applied a work-around that defaults to a long branch if it can't find the endpoint. This isn't as efficient as a short jump but it also doesn't crash.

Created Unassigned: It is possible to execute code not exposed in Flee via reflection [17732]

$
0
0
Flee exposes methods for reflection via GetType, allowing access to things not exposed to Flee explicitly.

For example these expressions:
```
1.GetType()
Result: "System.Int32" of type System.RuntimeType
1.GetType().Module
Result: "CommonLanguageRuntimeLibrary" of type System.Reflection.RuntimeModule
1.GetType().Module.getType("System.Environment")
Result: "System.Environment" of type System.RuntimeType
1.GetType().Module.getType("System.Environment").GetMethods()[25].Invoke( null; null )
Result: "Microsoft Windows NT 6.2.9200.0" of type System.OperatingSystem
```

The limitations as far as I can tell are that you can't use anything with arguments, but you can still gather a lot of information and do things like shut down the host application.

We've applied a patch that modifies IsMemberAccessible to find anything that returns a subclass of System.Type to be not accessible.

New Post: Avoid Evaluate by setting some property ?

$
0
0
HI,

Evaluate my expression using below code.

(T)DynamicExpression.Evaluate();

Is it possible that i called the above line by setting some flag or any other property and it will not evaluate my dynamic Expression ?

New Post: Ciloci.Flee.ExpressionContext

$
0
0
What is the maximum characters allowed for an expression to be evaluated using IGenericExpression interface using a method in C#. I am using it to evaluate a large expression and it is throwing ArgumentOutOfRangeException.

New Post: Maximum length of Expression

$
0
0
Any fixes you guys found for lengthy expression evaluation using FLEE?

New Post: An unhandled exception of type 'System.StackOverflowException' occurred in Ciloci.Flee.dll

$
0
0
The text to evaluate is of 15000 lines of text and functions.

Error

System.StackOverflowException : {Unable to evaluate expression.}

Error Code
Public Function Evaluate() As Object Implements IDynamicExpression.Evaluate
        Return MyEvaluator(MyOwner, MyContext, MyContext.Variables)
End Function
Stack Trace

at Ciloci.Flee.FleeILGenerator.ValidateLength() in D:\Probench\Libraries\flee-96133\Lib\InternalTypes\FleeILGenerator.vb:line 161
at Ciloci.Flee.Expression1.Compile(String expression, ExpressionOptions options) in D:\Probench\Libraries\flee-96133\Lib\InternalTypes\Expression.vb:line 98
at Ciloci.Flee.Expression
1..ctor(String expression, ExpressionContext context, Boolean isGeneric) in D:\Probench\Libraries\flee-96133\Lib\InternalTypes\Expression.vb:line 58
at Ciloci.Flee.ExpressionContext.CompileDynamic(String expression) in D:\Probench\Libraries\flee-96133\Lib\PublicTypes\ExpressionContext.vb:line 186
at Probench.Expressions.ExpressionProcessor.EvaluateMultipleStatements(String cacheKey, String semiColonSeparatedStatements, BaseContext context) in d:\Probench\Framework\Probench\Expressions\ExpressionProcessor.cs:line 73

""""""
Some more trace,
""""""
""""""
""""""
'w3wp.exe' (CLR v4.0.30319: /LM/W3SVC/4/ROOT-1-131448351375170646): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'.


Debug Print

The thread 0x2a40 has exited with code 259 (0x103).
The thread 0x354c has exited with code 259 (0x103).
The thread 0x35d0 has exited with code 259 (0x103).
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
ILGenerator length mismatch
---- Assert Long Message ----

Created Unassigned: Considering migrating to GitHub ? [17770]

$
0
0
As CodePlex will shut down soon, are you considering migrating to GitHub ?
Viewing all 96 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>