Jump to content

Recursive parsing algorithm


Recommended Posts

$parse="P10 P11 (P20) (P30 P31 (P320 P321) P33) P14"

The idea is that the innermost Parameters should be evaluated...in this example, P320 is a function that should be executed with the parameter P321, and the result is the parameter 2 of the function P30..You get the point...The functions are executed via call..

Quote

Together we might liveDivided we must fall

 

Link to comment
Share on other sites

  • Moderators

$parse="P10 P11 (P20) (P30 P31 (P320 P321) P33) P14"

The idea is that the innermost Parameters should be evaluated...in this example, P320 is a function that should be executed with the parameter P321, and the result is the parameter 2 of the function P30..You get the point...The functions are executed via call..

Can you give an example of how the functions would look (all of them), I must admit, I'm trying to soak in what your asking, but having an issue with it. Like are the Function Names defined by "(" and the Parameters for that function stop at ")"?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Well yes...PN0 is always the function name, and PNK is the K'th parameter of the function...

P10 P11 (P20) would be evaluated as follows:

the function P20 would be executed, and its result would be used in calling the function P10 with 2 parameters: P11 and the result of (P20)...What is put between brackets are functions w/ or w/o params, and others are just plain-text params...

Quote

Together we might liveDivided we must fall

 

Link to comment
Share on other sites

  • Moderators

Well yes...PN0 is always the function name, and PNK is the K'th parameter of the function...

P10 P11 (P20) would be evaluated as follows:

the function P20 would be executed, and its result would be used in calling the function P10 with 2 parameters: P11 and the result of (P20)...What is put between brackets are functions w/ or w/o params, and others are just plain-text params...

I hope someone can help you with that, I'm so confused, I feel like I'm playing the game "Where's Waldo". When I asked for what the functions would look like, I meant break it down like:
Func P20(P11, P13)
EndFunc
Etc... So maybe I could get an idea on how to "exactly" parse your string.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

The functions are generic..It doesn't matter how they look, because you can Call($function,$paramlist) where $paramlist is an array of parameters to the function...the function can have 100 parameters or just 2...it doesn't matter...

Quote

Together we might liveDivided we must fall

 

Link to comment
Share on other sites

  • Developers

something like this ?

$parse = "P10 P11 (P20) (P30 P31 (P320 P321) P33) P14"
$T_Parse = $parse
$T_Spos = 1
Dim $param[1] = [0]
Dim $ComboLevel = 0 
For $x = 1 To StringLen($parse)
    ; Find first Space
    If Stringmid($parse,$x,1) = "(" Then $ComboLevel = $ComboLevel + 1 
    If Stringmid($parse,$x,1) = ")" Then $ComboLevel = $ComboLevel - 1 
    If Stringmid($parse,$x,1) = " " And $ComboLevel = 0 Then 
        ReDim $param[UBound($param)+1]
        $param[0] = $param[0] + 1
        $param[UBound($param)-1] = StringMid($parse,$T_Spos,$x - $T_Spos)
        $T_Spos = $x + 1
    EndIf
Next
; Handle last param
If StringStripWS(StringMid($parse,$T_Spos,$x - $T_Spos),1) <> "" Then
    ReDim $param[UBound($param)+1]
    $param[0] = $param[0] + 1
    $param[UBound($param)-1] = StringMid($parse,$T_Spos,$x - $T_Spos)
EndIf
For $x = 1 To $param[0]
    ConsoleWrite($x & ":" & $param[$x] & @LF)
Next

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

That's quite funny..In one of my 10-minute-brainstorm-result implementations, I made something fairly similar, using a $level variable...:)..Sweet...Exactly what I was looking for..Thank you alot, JdeB

Quote

Together we might liveDivided we must fall

 

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...