Jump to content

manual interpretation of conditional statements


Recommended Posts

I am attempting to manually interpret conditional au3 statements

The only way I can think of to do this would be to manually define switches for every type of condition

and

or

not

=

>

<

I thought about it for a while, and using an array, and a 2 part switch with 2 4 part switches inside of them.

I was wondering if there was some way to use regex to first determine if and how many of "and" and "or" operators there are, and make an array of conditional statements between them.

Then use regex to determine the kind of condition not = < > then use a switch + arrays to determine if each condition is true or false.

Then in the end use a loop to somehow simulate a linear conditional statement based on "and" or "or" if an "and" statement return false if one statement is false and break loop, if "or" and one is true return "true" and break loop, if neither, simple return true or flase for theconditional statement.

This is being used to interpret conditional statements for my AU3DLL Plugin. (http://www.autoitscript.com/forum/index.php?showtopic=111993&st=0) Right now my brain in a little fried, and I am tired, so I WILL be taking a crack at this feat. The main places I need help is with the complex regex issues, although with all the confusing regex and arrays I did with my AU3DLL plugin any help would be appreciated as i literally dead putting my brain through that kind of thought process AGAIN. LOL

Edited by IchBistTod

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

That makes no sense. Why wouldn't the parent script just save the dynamic script line(s) to an .au3 file and run it?

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

IchBistTod,

determine if and how many of "and" and "or" operators there are, and make an array of conditional statements between them

Have you seen this? :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

IchBistTod,

Have you seen this? :(

M23

no... tyvm.

but it only determines 3 conditions?

is there a way to make it determine unlimited conditions within the function?

then actually execute the command within the function?

so all that wud have to bed done was pass the condition to the function then it would process the whole conditional statement and execute the condition, with no return needed?

I dont need a return. Just a function to process the conditional statement manually and execute the command.

I would be SO grateful if you could make the function do this.

Also I would like to ask you to join the AU3DLL Dev team, as this would add huge functionality to it.

Thanks SO much.

I am not feeling well right now and your help so far is greatly appreciated, in a few days i could likely complete the function to make it work as needed, but if you could do it before then i would be in your debt, as the faster it is finished, the faster we can make a HUGE contribution to the autoit community.

PM me with any further development and information.

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

  • Moderators

IchBistTod,

but it only determines 3 conditions?

No, it will determine as many conditions as there are in the passed string.

However, it does not look for (), so that you cannot make really complex groupings where several conditions are compared to something else - like this:

IF ($a < 3 AND $b < 4) OR ($c = 9 AND $d <77) THEN ......

This would have to be passed as follows (in pseudo-code):

; 1st pass
IF $a < 3 AND $b -> Set $Ret1
: 2nd pass
IF $c = 9 AND $d <77 -> Set $Ret2
; 3rd pass
IF $Ret1 OR $Ret2 THEN .......

I will see what I can do to overcome this - but do not hold your breath. :)

determine unlimited conditions within the function.....execute the command within the function

As long as the function knows the value of all the variables within the conditional statement and the command to execute, there is no reason why not. But how would you pass these to the function?

I dont need a return

Not even from the action that might be executed? So what is the purpose of the function? :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

IchBistTod,

I hope you are feeling better. Here is something that might cheer you up a bit. :)

Well, it was an interesting academic exercise even if I do not understand why you want it. :(

Here is a function which in my testing evaluates conditional expressions quite well up to level 2 - that is to say when there is one level of internal evaluations to make before evaluating the whole expression. It looks as if can deal with Level 3 if there is only one such evaluation and it is the final one to deal with - but I would not bet my life on it. ;)

; Declare variables for use in the examples
Global $sThisTest, $sText, $fRet

; This evaluates to True - Level 1
$sThisTest = "(True)"
$sText = "If " & $sThisTest & " Then Call('Function')"
$fRet = _EvalCondition($sText)
MsgBox(0, "Result", $sText & @CRLF & @CRLF & "AutoIt: " & Execute($sThisTest) & @CRLF & "UDF:     " & $fRet )

; This evaluates to False - Level 2 second
$sThisTest = "(True) And ((True) And Not(True))"
$sText = "If " & $sThisTest & " Then Call('Function')"
$fRet = _EvalCondition($sText)
MsgBox(0, "Result", $sText & @CRLF & @CRLF & "AutoIt: " & Execute($sThisTest) & @CRLF & "UDF:     " & $fRet )

; This evaluates to True - Level 2 first
$sThisTest = "((True) Or Not(True)) And (True)"
$sText = "If " & $sThisTest & " Then Call('Function')"
$fRet = _EvalCondition($sText)
MsgBox(0, "Result", $sText & @CRLF & @CRLF & "AutoIt: " & Execute($sThisTest) & @CRLF & "UDF:     " & $fRet )

; This evaluates to False - Level 2 first
$sThisTest = "((True) Or Not(False)) And (False)"
$sText = "If " & $sThisTest & " Then Call('Function')"
$fRet = _EvalCondition($sText)
MsgBox(0, "Result", $sText & @CRLF & @CRLF & "AutoIt: " & Execute($sThisTest) & @CRLF & "UDF:     " & $fRet )

; This evaluates to True - Level 2 twice
$sThisTest = "((True) And (True)) Or ((False) And (True))"
$sText = "If " & $sThisTest & " Then Call('Function')"
$fRet = _EvalCondition($sText)
MsgBox(0, "Result", $sText & @CRLF & @CRLF & "AutoIt: " & Execute($sThisTest) & @CRLF & "UDF:     " & $fRet )

; This evaluates to False - Level 2 three times
$sThisTest = "((True) And (False)) Or ((False) And (True)) Or ((True) And (True))"
$sText = "If " & $sThisTest & " Then Call('Function')"
$fRet = _EvalCondition($sText)
MsgBox(0, "Result", $sText & @CRLF & @CRLF & "AutoIt: " & Execute($sThisTest) & @CRLF & "UDF:     " & $fRet )

; This evaluates to False - Level 3 at end of Level 2 twice
$sThisTest = "((True) And (True)) And ((True) And ((True) And (False)))"
$sText = "If " & $sThisTest & " Then Call('Function')"
$fRet = _EvalCondition($sText)
MsgBox(0, "Result", $sText & @CRLF & @CRLF & "AutoIt: " & Execute($sThisTest) & @CRLF & "UDF:     " & $fRet )

Func _EvalCondition($sText)

    ; Separate expressions and action
    Local $aSplit = StringSplit(StringUpper($sText), "THEN", 1)
    Local $sExpressions = StringTrimLeft(StringStripWS($aSplit[1], 8), 2)

    ; Count the operators, replace them with hashes and declare array to hold the data
    Local $aAndOr = StringRegExp($sExpressions, "AND|OR", 3)
    Local $sHashExpressions = StringRegExpReplace($sExpressions, "AND|OR", "#####")
    Local $aResult[UBound($aAndOr) + 2][3] = [[$aSplit[2], UBound($aAndOr) + 1, 0]]

    ; Check if there are multiple expressions
    If UBound($aAndOr) = 0 Then

        ; Single expression
        $aResult[1][0] = $sExpressions

    Else

        ; Split the multiple expressions and add to array
        $aSplit = StringSplit($sHashExpressions, "#####", 1)
        For $i = 1 To $aSplit[0]
            $aResult[$i][0] = $aSplit[$i]
        Next

        ; Add operators to array
        For $i = 0 To UBound($aAndOr) - 1
            $aResult[$i + 2][1] = $aAndOr[$i]
        Next

        ; Set evaluation priorities and evaluate expressions
        Local $iOpeners, $iClosers, $nLevel = 0, $nAdd

        For $i = 1 To $aResult[0][1]

            ; Get the count of (
            StringRegExpReplace($aResult[$i][0], "\(", "")
            $iOpeners = @extended
            ; Get the count of )
            StringRegExpReplace($aResult[$i][0], "\)", "")
            $iClosers = @extended

            ; If additional ( we need to go up a level
            If $iOpeners > $iClosers Then
                ; Increase level
                $nLevel = $nLevel + (($iOpeners - $iClosers) * 100)
                ; Set level for this condition
                If $nLevel = 0 Then ; At start
                    $nLevel = 100
                Else
                    If $aResult[0][2] >= $nLevel Then
                        ; Could be more than one set at this priority level, so add increment
                        $nAdd = Number(StringTrimLeft(String($aResult[0][2]), 1))
                        $nLevel = $nLevel + $nAdd + 1
                    EndIf
                EndIf
                $aResult[$i][2] = $nLevel
                ; Store highest level
                If $nLevel > $aResult[0][2] Then $aResult[0][2] = $nLevel
                ; Trim excess (
                $aResult[$i][0] = StringTrimLeft($aResult[$i][0], $iOpeners - $iClosers)

            ElseIf $iOpeners < $iClosers Then

                ; Set level for this condition
                $aResult[$i][2] = $nLevel
                ; Decrease level for subsequent expressions
                $nLevel = Int($nLevel) - ($iClosers - $iOpeners) * 100
                ; Trim excess )
                $aResult[$i][0] = StringTrimRight($aResult[$i][0], $iClosers - $iOpeners)

            Else

                ; Set level for this condition
                If $nLevel = 0 Then ; At start
                    $nLevel = 100
                Else
                    If $aResult[0][2] >= $nLevel Then
                        ; Could be more than one set at this priority level, so add increment
                        $nAdd = Number(StringTrimLeft(String($aResult[0][2]), 1))
                        $nLevel = $nLevel + $nAdd + 1
                    EndIf
                EndIf
                $aResult[$i][2] = $nLevel

            EndIf

            ; Evaluate expression and store result
            $aResult[$i][0] = Execute($aResult[$i][0])

        Next

        ; Now evalute the True/False expressions in priority order
        Local $iPriority, $nThisPriority, $sExpression

        ; Start with the highest priority
        For $iPriority = Int($aResult[0][2] / 100) * 100 To 0 Step -100
            ; Move through expressions
            For $i = 1 To $aResult[0][1]
                If Int($aResult[$i][2] / 100) * 100 = $iPriority Then

                    ; We have found the highest priority
                    $nThisPriority = $aResult[$i][2]

                    ; Reduce priority of result for next pass
                    If $nThisPriority > 200 Then
                        $aResult[$i][2] = $nThisPriority - 100
                    Else
                        $aResult[$i][2] = 0 ; Needed for final check
                    EndIf

                    ; Start expression construction
                    $sExpression = $aResult[$i][0]
                    ; Now add other expressions at the same priority level
                    For $j = $i + 1 To $aResult[0][1]

                        If $aResult[$j][2] = $nThisPriority Then
                            ; Add the operator and expression to the condition
                            $sExpression &= " " & $aResult[$j][1] & " " & $aResult[$j][0]
                            ; Prevent consideration of expression during subsequent passes
                            $aResult[$j][2] = 9999
                        ElseIf  $aResult[$j][2] = 9999 Then
                            ; Skip
                        ElseIf $aResult[$j][2] <> $nThisPriority Then
                            ; Found another priority expression so stop
                            ExitLoop
                        EndIf
                    Next
                    ; Evaluate the expression and store
                    $aResult[$i][0] = Execute($sExpression)

                    ; Reset the counter to the next expression to check
                    $i = $j - 1

                EndIf
            Next
        Next
    EndIf

    ; Check whether to action
    If $aResult[1][0] = True Then
        Return True; Execute($aResult[0][0]) ; Action
    Else
        Return False ;SetError(1, 0, 0) ; Error
    EndIf

EndFunc

The examples are written using True/False only for convenience, but you can put real expressions in there as the function will evaluate them correctly.

You must use brackets to surround every expression - the function uses them to set the evaluation priority. So no shortcuts - you must be absolutely pendantic as the examples show.

At the moment the function just returns True/False - you can see where the Execute("Action") would occur.

So there you have it. I am afraid I am not spending any more time on it - so if it does not do what you want you are on your own. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...