Logical expression evaluator

hi,
Can anybody provide code snippet/example or any reference to evaluate
a String ?
thanx in advance.

You can use Jacc (find it on Google) to parse and evaluate the expression.
But, you can also create a tree representing the expression and evaluate it each time you want :
abstract class Node {
   public abstract Object evaluate();
abstract class BinaryOperator extends Node {
   protected Node leftOperand;
   protected Node rightOperand;
   protected BinaryOperator (Node lo, Node ro) {
      leftOperand =lo;
      rightOperand = ro;
abstract class Leaf extends Node{
   protected Object value;
class Value extends Leaf {
   public Value(Object val) {
       value = val;
   public Object evaluate() {
       return value;
class Variable extends Leaf {
   String name;
   public Variable (String name) {
       this.name= name;
   public void setValue(Object val) {
      value = val;
   public Object evaluate() {
       return value;
class Equal extends BinaryOperator {
   public Equal(Node lo, Node ro) {
      super(lo,ro);
   public Object evaluate() {
      return new Boolean(leftOperand.evaluate().equals(rightOperand.evaluate()));
class NotEqual extends BinaryOperator {
   public NotEqual(Node lo, Node ro) {
      super(lo,ro);
   public Object evaluate() {
      return new Boolean(!leftOperand.evaluate().equals(rightOperand.evaluate()));
class Inferior extends BinaryOperator {
   public Inferior (Node lo, Node ro) {
      super(lo,ro);
   public Object evaluate() {
      Object o1 = leftOperand.evaluate();     
      Object o2 = rightOperand.evaluate();
      if (o1 instanceof Number && o2 instanceof Number) {
      return new Boolean(((Number)o1).doubleValue()<((Number)o2).doubleValue());
      return new Boolean(false);
class Or extends BinaryOperator {
   public Or(Node lo, Node ro) {
      super(lo,ro);
   public Object evaluate() {
      Object o1 = leftOperand.evaluate();     
      Object o2 = rightOperand.evaluate();
      if (o1 instanceof Boolean && o2 instanceof Boolean ) {
      return new Boolean(((Boolean)o1).booleanValue()||((Boolean)o2).booleanValue());
      return new Boolean(false); // if correct it never happens
...After that you build the tree :
Variable var1 = new Variable("STN");
Value v1 = new Value("E");
BinaryOperator bo1 = new Equal(var1,v1);
Variable var2 = new Variable("STN");
Value v2 = new Value("R");
BinaryOperator bo2 = new Equal(var2,v2);
BinaryrOperator bo3 = new Or(bo1,bo2);
// We instanciate the value of the variables for each row :
for (int i = 0; i<rowNumber;i++) {
    var1.setValue(stn);
var2.setValue(stn[i]);
res = bo3.evaluate();
//You must make this automatically.
I hope this helps,
Denis

Similar Messages

  • Regular expression evaluation with logical operator

    Hi All,
    I am bit confuse with expression evaluation with logical operator. I am trying to understand below expression.
    eXa.getTrue() && eXa.getFalse() || eXa.getFalse() && eXa.getTrue() || eXa.getFalse() comes as false and True Count: 1 False Count: 3
    As per understanding it should be true with True Count: 1 False Count: 3
    it should execute 1st getTrue() and then 1stGetFalse() and then 2nd getfalse() and should skip 2nd getTrue() and execute 3rd fetFalse()
    eXa.getTrue() && eXa.getTrue() || eXa.getFalse() && eXa.getTrue() || eXa.getFalse() comes as true and True Count: 2 False Count: 0
    As per understanding it should be true with True Count: 3 False Count: 0
    it should execute 1st 2 getTrue() and skip 1st getFalse() and then execute 3rd getTrue() and skip last getFalse().
    eXa.getTrue() || eXa.getFalse() && eXa.getFalse() || eXa.getTrue() && eXa.getFalse() comes as true and True Count: 1 False Count: 0
    As per understanding it should be true with True Count: 2 False Count: 2
    it should execute 1st getTrue() and skip 1st getFalse() and then execute 2nd getFalse() and then execute 2nd getTrue() and then 3rd getFalse()
    Please help me to understand above expressions.
    Here is the methods definition:
    private boolean getTrue() {
              trueCount++;
              boolean retrunValue = 4 > 3;
              return retrunValue;
    private boolean getFalse() {
              falseCount++;
              boolean retrunValue = 3 > 4;
              return retrunValue;
    Thanks for ur help

    >
    adding parenthesis to make order of ops more obvious. adding "?" to show un-executed calls.
    (eXa.getTrue() && eXa.getFalse()) || (eXa.getFalse() && eXa.getTrue()) || eXa.getFalse()  comes as false and True Count: 1 False Count: 3
    (T && F) = F
    (F && ?) = F
    (F) = F
    F || F || F = F
    (eXa.getTrue() && eXa.getTrue()) || (eXa.getFalse() && eXa.getTrue()) || eXa.getFalse()  comes as true and True Count: 2 False Count: 0
    (T && T) = T
    (? && ?) = ?
    (?) = ?
    T || ? || ? = T
    eXa.getTrue() || (eXa.getFalse() && eXa.getFalse()) || (eXa.getTrue() && eXa.getFalse())  comes as true and True Count: 1 False Count: 0
    (T) = T
    (? && ?) = ?
    (? && ?) = ?
    T || ? || ? = T

  • I am looking for an boolean and numeric expression evaluator. I want to be able to compare ( ,=, , or, not, and, nand, etc)and evaluate boolean/numeric expression.

    I am looking for an boolean and numeric expression evaluator. I want to be able to compare (>,=, <, or, not, and, nand, etc)and evaluate boolean/numeric expression. Does anyone know if there is any code samples anywhere. If anyone has any input, I would greately appreciate it.

    The problem is that I have to enter a string of that type (any random string), and the program should go and calculate the result for the whole stirng, by looking at which parts to calculate first (figuring out precedence), second, etc. This is like a calculator, you don't know what the user is going to enter next, so I can't just use the boolean palatte. I could use it if the equation was always of the form "a 'operator' b", where the operator is any logic or comparison operator. But that is not what I am trying to accomplish.
    Can you do logic in the formula node? I think it only allows numeric values for inputs and outputs, it doesn't let you enter in and output booleans and stuff..does it?
    Thanks,
    Yuliya

  • Algorithm for Expression Evaluator

    Hi,
    Can any one help me in finding out the algo of Expression Evaluator,Changing Pre fix to Post Fix and vise versa.
    Tx in advance.
    from
    gomes_deb

    There is a math expression parser at http://www.bestcode.com. It forms a tree structure where nodes are operators, functions, variables, numbers. Each node of the tree has children (for example parameters of a function are it's children in this tree). So, if you have a "x+sin(y)", the tree is like this:
    ___+
    _x     sin
    _______y
    Then when it is time to evaluate, you set the values of X and Y and call evaluate() method and it tells you what the result is.
    The java bean is called JbcParser. It's features are:
    *Easy to use, simple class API.
    *Comes with predefined functions.
    *Users can create custom functions/variables.
    *Optimization: Constant expression elimination for repeated tasks.
    Analytical Operators: +, -, /, , ^(power)
    *Logical Operators: =(equals),&(and),|(or),!(not), <>(not equals), <=(less than or equals), >=(greater than or equals)
    *Paranthesis: (, {, [
    *Functions in the form of: f(x, y, z, ...)
    *Function parameters are not calculated until needed.
    *List of predefined functions is available in the documentation.
    *Java source code is included.
    An example of a simple expression is : LN(X)+SIN(10/2-5)
    When parsed, this expression will be represented as: since the SIN(10/2-5) is in fact SIN(0) which is a constant and is 0.
    Thus, in a loop, if you change the value of X and ask for the value of the expression, it will be evaluated quite fast since SIN(10/2-5) is not dependent on X.
    X and Y are predefined variables. You can create your own variables as needed.
    There are many predefined mathematical functions. They are listed in documentation. You can create your functions as needed. IF logic is implemented through a predefined IF(A,B,C) function. Similar logical functions can be created as needed.
    It is located at: http://www.bestcode.com/html/jbcparser.html

  • LOGIC EXPRESS 9 HELP!

    what features does logic express 9 have for vocal editing like reverb delay?

    Hi,
    This is the kind of broad question which would be best researched by googling.
    I just did a Google search for "logic express 9 vocal editing":
    I quickly found this link to the 195 page Logic Express 9 Effects PDF file.( It was the 6th entry on Google's list.):
    http://documentation.apple.com/en/logicexpress/effects/Logic%20Express%209%20Eff ects%20(en).pdf
    You can download that file and search it for the word "vocal". I tried it and got 51 matches.
    Additionally, a Google search has the potential to find many other useful resources for more nuanced information including related youtube videos, recommendations, evaluation, tips, etc.
    When you do a Google search, it automatically looks at related information in all of the Logic Apple Support Communities, such as this one, along with anything else it can find.
    I hope this helps,
    John

  • How to create an ABAP Query with OR logical expression in the select-where

    Hi,
    In trying to create an ABAP query with parameters. So it will select data where fields are equal to the parameters entered. The default logical expression is SELECT.. WHERE... AND.. However I want to have an OR logical expression instead of AND.. how can I attain this??
    Please help me on this.. Points will be rewarded.
    Thanks a lot.
    Regards,
    Question Man

    Hi Bhupal, Shanthi, and Saipriya,
    Thanks for your replies. But that didn't answer my question.
    Bhupal,
    You cannot just replace AND with OR in an ABAP QUERY. ABAP QUERY is a self generated SAP code. You'll just declare the tables, input parameters and output fields to be displayed and it will create a SAP standard code. If you'll try to change the code and replace the AND with OR in the SAP standard code, the system will require you to enter access key/object key for that particular query.
    Shanthi,
    Yes, that is exactly what need to have. I need to retireve DATA whenever one of the conditions was satisfied.
    Saipriya,
    Like what I have said, this is a standard SAP code so we can't do your suggestion.
    I have already tried to insert a code in the ABAP query (there's a part there wherein you can have extra code) but that didn't work. Can anybody help me on this.
    Thanks a lot.
    Points will be rewarded.
    Regards,
    Question Man

  • Dynamic Logical Expressions in ABAP: IF (lt_cond)...

    is it possible to have a dynamically constructured logical expression?
    I have a condition I need to use in an IF, but I want to avoid hard-coding, so I dynamicallybuild it.
    for a simple example:
    CONCATENATE ITAB-f1
               'EQ'
               varValue
               INTO lt_cond SEPARATED BY SPACE.
    IF (lt_cond).
      WRITE:/ 'Success'.
    ENDIF.
    Is it possible to do this?
    NL

    I am trying to use the macro to check an IF (cond).
    cond is a dynamically constructed condition.
    The bold part of my code way below is my problem area.
    I'm having no trouble getting COND constructed. But I am having trouble between my macro and the processing as my error always tells me I'm calling my macro without 2 actual parameters. Or when I DEFINE my macro with &1 instead of &1 &2, I get 'incorrect logical expression'.
    I've read all the documentation I can find on this, but i still cannot figure out why my macro is not processing.
    Code is lengthy, but if you can, please help.
    I'm anticipating the output to be 'FAILURE' at this point. I just want the condition COND to be processed.
    data: tabfield(20) type c,
          orcheck type I,
          cond type string.
    DATA: BEGIN OF ITAB_NOTIDX OCCURS 0,
          FIELD LIKE ZDOLTARC02-SEARCHFLD,
          VALUE LIKE ZDOLTARC03-VALUE,
          STRUCTURE LIKE ZDOLTARC02-STRUCTURE,
          AOBJ LIKE ZDOLTARC02-A_OBJ,
          END OF ITAB_NOTIDX.
    DATA: BEGIN OF ITAB_AOBJ OCCURS 0,
          AOBJ LIKE ZDOLTARC02-A_OBJ,
          END OF ITAB_AOBJ.
    DATA: ITAB_AOBJF LIKE ITAB_AOBJ.
    DATA: ITAB_NOTIDXF LIKE ITAB_NOTIDX.
    DATA: varAOBJ LIKE ZDOLTARC02-A_OBJ.
    ITAB_NOTIDXF-FIELD = 'LIFNR'.
    ITAB_NOTIDXF-VALUE = '123'.
    ITAB_NOTIDXF-STRUCTURE = 'BKPF'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'LIFNR'.
    ITAB_NOTIDXF-VALUE = 'ABC'.
    ITAB_NOTIDXF-STRUCTURE = 'BKPF'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'LIFNR'.
    ITAB_NOTIDXF-VALUE = '001'.
    ITAB_NOTIDXF-STRUCTURE = 'BKPF'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'SAKNR'.
    ITAB_NOTIDXF-VALUE = '111'.
    ITAB_NOTIDXF-STRUCTURE = 'BSEG'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'SAKNR'.
    ITAB_NOTIDXF-VALUE = '222'.
    ITAB_NOTIDXF-STRUCTURE = 'BSEG'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'KUNNR'.
    ITAB_NOTIDXF-VALUE = 'CCC'.
    ITAB_NOTIDXF-STRUCTURE = 'BSEG'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'KUNNR'.
    ITAB_NOTIDXF-VALUE = 'DDD'.
    ITAB_NOTIDXF-STRUCTURE = 'BSEG'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    LOOP AT ITAB_NOTIDX.
      WRITE:/ ITAB_NOTIDX-FIELD, ITAB_NOTIDX-VALUE, ITAB_NOTIDX-STRUCTURE, ITAB_NOTIDX-AOBJ.
    ENDLOOP.
    DATA: VARFIELDNAME LIKE ZDOLTARC02-FIELD.
    CONCATENATE cond
               INTO Cond.
    SORT ITAB_NOTIDX BY AOBJ FIELD.
    varFieldName = Itab_NOTIDX-FIELD.
    ORCHECK = 0.
    ITAB_AOBJF = 'FI_DOCUMNT'.
    APPEND ITAB_AOBJF TO ITAB_AOBJ.
    LOOP AT ITAB_AOBJ.
       MOVE ITAB_AOBJ-AOBJ TO varAOBJ.
       WRITE:/ varAOBJ.
       LOOP AT ITAB_NOTIDX WHERE AOBJ EQ varAOBJ.
               WRITE:/ 'LOOP TEST'.
            IF ITAB_NOTIDX-FIELD EQ varFieldName.
                 WRITE:/ VARFIELDNAME.
                 IF ORCHECK <> 0.
                 CONCATENATE cond
                                'OR'
                                INTO cond SEPARATED BY SPACE.
                 ENDIF.
                 CONCATENATE ITAB_NOTIDX-STRUCTURE
                        ITAB_NOTIDX-FIELD
                        INTO tabfield.
                 CONCATENATE cond
                        tabfield
                        'EQ'
                        '''' ITAB_NOTIDX-value ''''
                        INTO cond SEPARATED BY SPACE.
                 ORCHECK = ORCHECK + 1.
            ELSE.
                MOVE ITAB_NOTIDX-FIELD TO varFieldName.
              WRITE:/ '2', VARFIELDNAME.
                CLEAR TABFIELD.
              ORCHECK = 0.
              CONCATENATE ITAB_NOTIDX-STRUCTURE
                    varFieldName
                    INTO TABFIELD.
                 CONCATENATE cond
                        'AND'
                        TABFIELD
                    'EQ'
                    '''' ITAB_NOTIDX-VALUE ''''
                        INTO cond SEPARATED BY SPACE.
                    ORCHECK = ORCHECK + 1.
            ENDIF.
       ENDLOOP.
    ENDLOOP.
    CONCATENATE COND
                INTO COND.
    write:/ COND. "constructed properly
    <b>DEFINE my_dynamic_check.
    if &1, &2.
      write:/ 'Success'.
    else.
      write:/ 'Failed'.
    endif.
    END-OF-DEFINITION.
    my_dynamic_check (cond).</b>

  • Logical expression( = , =, , ) in read statement

    Hi All,
    Is it possible to use the logical expressions like (<= , >=, <, >) in the read statement?

    While you can only use "=" with the READ statement, you can use the READ statement to position the cursor at the first record you want and then use the LOOP with your operators to get only those records you want (assuming standard tables that have been correctly sorted). This can be very efficient.
    There have been many discussion about this in the forums. Please search and you'll see them.
    Rob

  • Logical expressions in Link editor

    Hi all,
    Is it possible to define logical expressions (using AND, OR) in the Link editor of BLS or are we left with only using the Conditional Action block? Thanks...

    Yes it is.
    For AND : <<Condition1>> <b>&&</b> <<Condition2>>
    For OR : <<Condition1>> <b>||</b> <<Condition2>>
    You can use the <b>double ampersand (&&)</b> for <b>AND</b> and <b>double pipe (||)</b> for <b>OR</b>

  • [svn] 3045: Fix FB-13900: Expression Evaluator: 'is' and 'as' expressions return 'Target player does not support function calls'

    Revision: 3045
    Author: [email protected]
    Date: 2008-08-29 10:59:25 -0700 (Fri, 29 Aug 2008)
    Log Message:
    Fix FB-13900: Expression Evaluator: 'is' and 'as' expressions return 'Target player does not support function calls'
    Ticket Links:
    http://bugs.adobe.com/jira/browse/FB-13900
    Modified Paths:
    flex/sdk/trunk/modules/debugger/src/java/flash/tools/debugger/concrete/BinaryOp.java
    flex/sdk/trunk/modules/debugger/src/java/flash/tools/debugger/concrete/PlayerSession.java

    Revision: 3045
    Author: [email protected]
    Date: 2008-08-29 10:59:25 -0700 (Fri, 29 Aug 2008)
    Log Message:
    Fix FB-13900: Expression Evaluator: 'is' and 'as' expressions return 'Target player does not support function calls'
    Ticket Links:
    http://bugs.adobe.com/jira/browse/FB-13900
    Modified Paths:
    flex/sdk/trunk/modules/debugger/src/java/flash/tools/debugger/concrete/BinaryOp.java
    flex/sdk/trunk/modules/debugger/src/java/flash/tools/debugger/concrete/PlayerSession.java

  • Help! Logic Express 8 does not work on my Mac Pro with OS 10.5.1

    Hello, I hope somebody around here is able to help me.
    I have got a new Mac Pro with one Quad core processor since yesterday and it works fine except for Logic Express 8 (version 8.0.1). Whenever I start Logic the program crashes as soon as "Core Audio initialisieren" is shown in the display. I have tried to reinstall the program, deleted it completely and installed it again. It is always the same.
    Has anyone else experienced this problem? What can I do about it? I am a musician and I really need Logic Express to run.

    Confused. 10.6 is DVD based. Only Lion and above are downloads.
    And best install is not to upgrade. Do a clean install  - on another drive.
    Corrupt partition tables or bad sectors or no room to adjust the partitions or the directory is corrupt.
    ERASE the drive if Repair Disk didn't work.

  • Loops in Logic Express

    First of all I best say that I am new to Logic Express and Garageband, in fact the Mac thing so forgive the basic nature of this post. I have had some funny goings on with my mac since a failed software install so I decided to rebuild everything including the OS. Having re-installed Garageband and Logic Express I find most of the loops are missing. Some are there but all drum loops and others have gone. I tried to look up options to see if there is a tick box to install them but nothing. If I look in library, the loop directory is also missing. Can anyone suggest anything?
    Thanks
    Tetleyted

    Thanks for the reply. took a look but the directory structure as follows: HD/Library/Audio/Apple Loops/User Loops (Apple doesn't exist. I have a feeling that garageband and Logic Express hasn't completed the install. I have tried to re-run it but the same thing happened - no loops. Any suggestions welcomed.

  • Some organs don't play in new Logic Express files after JamPacks installed

    After loading only the instruments from the Symphony Orchestra and World Music GarageBand Jam Packs, I lost the ability to hear most of the organs available in Logic Express and all of the organs available in GarageBand after inserting them into Logic Express tracks. These same organ sounds still play in any Logic Express file set up prior to the installation of the JamPacks and they continue to play in GarageBand. Can an uninstall/reinstall of Logic Express 7.2.3 be a fix for this or is there an easier way to return the lost instruments to Logic Express?
    1.83 GHz Intel Core Duo iMac   Mac OS X (10.4.8)   Midisport 4x4, iControl

    The loss of instrument sounds in Logic Express had nothing to do with the installation of GarageBand JamPacks. The midi channel setting in the Inspector box of the Arrange window in Logic Express needed to be set to channel 1 to get midi data from other than channel 1 to play some of the inserted CoreAudio instruments. I don't understand what's going on but now I'm able to get the instruments that would not play.

  • How to connect my Alesis to Logic Express Pro, running on an Intel Mac Mini

    Hi,
    would anyone possibly have an idea how to connect my Alesis Multimix 8 USB to Logic Express 7,2?
    The Alesis has a USB out. But I don't see anything in the L/E documentation on USB connections.
    I'm hopeful there's another way.
    Thanks very much.
    -peter

    LE documentation won't give instructions for use of 3rd party equipment, except possibly generically.
    Have you downloaded the latest drivers? If it is a USB item, perhaps you are meant to plug in the USB cable rather than wishing it was something else.

  • Logic Express wont open Because of mountain lion!

    recently upgraded to mountain lion, and noticed shortly after that logic express 9 will not open in any form.
    please help me get logic express running again!

    Hi
    You seem to have double posted?
    https://discussions.apple.com/message/21033857#21033857
    CCT

Maybe you are looking for

  • Issues after migrating from 3.0.6.6.5 to 3.0.9.8.3A

    G'day All, Over the last week or so I have performed some test migrations using copies of our production Portal environment and here are some of the issues that I have encountered. ISSUE 1 - Performance Using a stopwatch (primitive, I know) I visited

  • How to set default paper direction

    I would like to reset the default paper direction. After having the default be a portrait direction for several years, things suddenly changed and now all applications automatically print in landscape - with the exception of Word for Mac. I mostly pr

  • Indesign CS6 crashes when opening docs

    Hello, since upgrading our macs to OSX 10.9 & Adobe CS6 we have strange crashes of Indesign. It´s hard to reproduce because it happens irregular ...mostly when switching between programs and opening an ID-doc afterwards. Without switching to other pr

  • TS3694 error message when uploading new ios 6, now phone does not work..

    USB pic on screen and phone wont do anything, itunes wont connect. I have updated itunes and restarted computer and still nothing....please help!!

  • How to remove Gmail "sent message" label

    Hi all, I am using Lion in one of my Mac and I found one problem I am using my Gmail account in Lion Mail When I use Lion Mail to send/reply a mail, Gmail on brower will show a "sent message" label on that mail. What should I do to prevent it? I mean