Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuickLib.Expression have bug and Some advice #60

Open
Midas-Li opened this issue Feb 3, 2021 · 4 comments
Open

QuickLib.Expression have bug and Some advice #60

Midas-Li opened this issue Feb 3, 2021 · 4 comments

Comments

@Midas-Li
Copy link

Midas-Li commented Feb 3, 2021

First, it was found that priority processing was not supported, causing some partial errors:
Assert(true, TExpressionParser.Validate(5, '(0.3 < 8) or (5 < 4) and (2 = 1)')); //false is err
Assert(true, TExpressionParser.Validate(5, '(8 > 3) or (5 > 4) and (2 = 1)')); //false is err

Some statements cannot be executed
// PRN(TExpressionParser.Validate(5,'8<1'));
// PRN(TExpressionParser.Validate(5,'8 < 1 or 5 > 4 '));

Unable to support addition, subtraction, multiplication and division. Hope to support common functions as well as custom functions

@exilon
Copy link
Owner

exilon commented Feb 6, 2021

Sorry, as you can see in readme, TExpressionParser was created to validate object properties. You need to pass and object as first parameter, and an expression as second param, where each condition can be a property or a property of a property of that object:

 if TExpressionParser.Validate(user,('(Age > 30) AND (Dept.Name = "Financial")') then
  begin
    //do something
  end;

But, if you pass a integer as first param, TExpression replaces first part of every condition with that integer.

 TExpressionParser.Validate(20,('(a > 30) AND (a < 40)') //will be transformed as (20 > 30) AND (20 < 40)
 TExpressionParser.Validate(5,('(8,3 > 2) AND (50 < 40)') //will be transformed as (5 > 2) AND (5 < 40)

However, I updated Expressions to support Validate without first param:
``
TExpressionParser.Validate(''(8 > 3) or ((5 > 4) and (2 = 1))')

Priority in TExpressions are defined with parenthesis. Expressions are processed from outer to inner parenthesis and from left to right. See new sample in QuickLib\samples\delphi.

@Midas-Li
Copy link
Author

Midas-Li commented Feb 8, 2021

Thanks for your guidance.
In fact, I also made a similar module, it can also do expression evaluation, and without the need for logical expressions with parentheses and the operator and support addition, subtraction, multiplication and division operations, do you have any plans to expand your current module?
If you are interested, I can send it to you for reference.

@exilon
Copy link
Owner

exilon commented Feb 9, 2021

Yes, of course.

@Midas-Li
Copy link
Author

Attached is the file, please receive it.
Calc.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants