English
Forum

Problems with Matheparser (heul!)

 

Jac
de
Lad
Hello Community. I write strain in a Matheparser. unfortunately scheitere I following situation (View source under): The Parser accounts everything correctly., but with the number 1087 accounts it 7 from the String (probierts time from!). it must on the procedure GetBefore lying, because The gives as Startbuchstaben for number 4 back, should but 1 give back. can someone help? (someone the much Time has, because the View source is utterly experimentell, not comments and gives yet Unmengen of Debug-Info from, vielle kanns Yes time someone try, Feedback, too ask, would me helpful, ichsitze now namely already hours on the trouble)!
CompileMarkSeparation
declare y1%,y2%

proc Operator

    Parameters f$
    declare a%

    whileloop 5

        if Instr(Mid$("+-*/^",&Loop,1),f$)

            inc a%
            Break

        endif

    wend

    Return a%

endproc

proc GetBefore

    Parameters b$,r%
    Print "Durchsuche ",b$
    y1%=r%-1

    while And(InStr(Mid$(b$,y1%,1),".9876543210"),GT(y1%,1))

        Dec y1%

    wend

    Return Val(Mid$(b$,y1%,2))

endproc

proc GetAfter

    Parameters b$,r%
    y2%=r%+1

    while Instr(Mid$(b$,y2%,1),".9876543210")

        Inc y2%

    wend

    Return Val(Mid$(b$,r%+1,y2%-r%))

endproc

proc Parse

    Parameters fx$
    declare z$,y$,d%,c%,x$,xl%,erg$,a%,erg!,x1!,x2!,in%
    fx$=Translate$(Translate$(Translate$(Translate$(Translate$(Translate$(fx$,",","."),"{","("),"[","("),"}",")"),"]",")")," ","")
    Print "Optimierte Formel: "+fx$
    Noch abfragen ob Anz("(")=Anz(")")!!!

    while Instr("(",fx$)

        d%=Len(fx$)

        while Neq$("(",Mid$(fx$,d%,1))

            Dec d%

        wend

        x$=Right$(fx$,Len(fx$)-d%)
        x$=Left$(x$,Instr(")",x$))
        xl%=Len(x$)
        x$=Del$(x$,Len(x$),1)

        if Operator(x$)

            Print "Parse "+x$+"..."

            whileloop 5

                in%=Instr(Mid$("^*/+-",&Loop,1),x$)
                c%=&Loop

                while in%

                    a%=in%
                    x1!=GetBefore(x$,a%)
                    x2!=GetAfter(x$,a%)

                    if Equ(c%,1)

                        Print "Potenz"
                        erg!=x1!^x2!

                    elseif Equ(c%,2)

                        Print "Mal"
                        erg!=x1!*x2!

                    elseif Equ(c%,3)

                        Print "Durch"
                        erg!=x1!/x2!

                    elseif Equ(c%,4)

                        Print "Plus"
                        erg!=x1!+x2!

                    else

                        Print "Minus"
                        erg!=x1!-x2!

                    endif

                    y$=Del$(x$,1,y2%-1)
                    z$=If(Equ(y1%,1),"",Left$(x$,y1%-1))
                    x$=z$+Str$(erg!)+y$
                    Print Str$(x1!)+","+Str$(x2!)+"="+Str$(erg!)
                    Print "Neue Teilformel: "+x$
                    in%=Instr(Mid$("^*/+-",c%,1),x$)
                    waitinput

                wend

            wend

        endif

        fx$=Left$(fx$,d%-1)+Str$(erg!)+Right$(fx$,Len(fx$)-d%-xl%)
        Print "Neue Formel: "+fx$

    wend

    Return fx$

endproc

declare s$
cls
s$="(((3+5)*2+3*(12+345))+12)"
Print "Formel: "+s$
Print "Ergebnis: "+Parse(s$)
waitinput

Jac
 
Profan² 2.6 bis XProfan 11.1+XPSE+XPIA+XPRR (und irgendwann XIDE)
Core2Duo E8500/T2250, 8192/1024 MB, Radeon HD4850/Radeon XPress 1250, Vista64/XP
02/08/06  
 




Michael
Wodrich
you should try, the whole with Bleistift and paper nachzuvollziehen. SEI THE COMPUTER.

here your code with Kommentaren and nachfolgend The schrittweise dissolution the Program (anyway The important steps).
CompileMarkSeparation
Declare Y1%,Y2%

Proc Operator

    Parameters F$
    Declare A%

    Whileloop 5

        If Instr(Mid$("+-*/^",&Loop,1),F$)

            Inc A%
            Break

        Endif

    Wend

    Return A%
    *** zeigt, wieviele unterschiedliche Operatoren vorhanden sind
    *** ermittelt aber nicht, wieviele Operatoren insgesamt da sind
    *** (jeder Operator wird nur einmal (als erstes Vorkommen) gezählt

Endproc

Proc Getbefore

    Parameters B$,R%
    Print "Durchsuche ",B$
    Y1% = R% - 1

    While And(Instr(Mid$(B$,Y1%,1),".9876543210"),Gt(Y1%,1))

        *** Abbruchbedingung "Y1% > 1" sollte VOR "Mid$(..,Y1%,..)" stehen.
        *** (auch der Eintritt in die Schleife muß beachtet werden: was, wenn Y1% = 0 am Anfang)
        Dec Y1%

    Wend

    Return Val(Mid$(B$,Y1%,2))
    *** FEHLER: die Länge von Mid$ steht fest auf 2
    *** Außderdem wird Y1% auf ein Zeichen vor der ersten Ziffer oder auf Pos.1 stehen

Endproc

Proc Getafter

    Parameters B$,R%
    Y2% = R% + 1

    While Instr(Mid$(B$,Y2%,1),".9876543210")

        *** Ein String ist irgendwann mal zu Ende: ABFANGEN (B$)
        *** (Microsoft patcht immer noch an seinen programmierten Pufferüberläufen herum.)
        *** (Das hätten sie sich gespart, wenn sie immer alle Sonderfälle abgefangen hätten.)
        Inc Y2%

    Wend

    Return Val(Mid$(B$,R%+1,Y2%-R%))
    *** Probe:
    *** B$ = "(12+345"
    *** R% = 4
    *** Y2% = 8
    *** Val( Mid$("(12+345",5,4) ) == 345 ** ABER: es wurde 1 Stelle zuviel berechnet (4)

Endproc

Proc Parse

    Parameters Fx$
    Declare Z$,Y$,D%,C%,X$,Xl%,Erg$,A%,Erg!,X1!,X2!,In%
    *** die folgenden Translates sehen bei mir wunderschön eingerückt aus
    *** und die Parameter dann wieder ausgerückt - war sehr übersichtlich  ;-(
    Fx$ = Translate$(
    Translate$(
    Translate$(
    Translate$(
    Translate$(
    Translate$(Fx$,",","."),   wandle Komma in Punkt
    "{","("),   wandle geschweifte Klammer in runde K.
    "[","("),   wandle eckige K. in runde K.
    "}",")"),   wandle geschweifte Klammer in runde K.
    "]",")"),   wandle eckige K. in runde K.
    " ","")  entferne alle Leerzeichen
    Print "Optimierte Formel: "+Fx$
    Noch abfragen ob Anz("(")=Anz(")")!!!
    ***   If NEq(
    ***          ( Len(Fx$) - Len(Translate$(Fx$,"(","")) ),
    ***          ( Len(Fx$) - Len(Translate$(Fx$,")","")) )
    ***         )
    ***     Teletubby_Modus(ein)
    ***       say "ohh-ohhh"
    ***     Teletubby_Modus(aus)
    ***   EndIf

    While Instr("(",Fx$)

        *** ohne Klammern macht der Parser dicke Backen...
        D% = Len(Fx$)

        While Neq$("(",Mid$(Fx$,D%,1))

            Dec D%

        Wend

        X$ = Right$(Fx$,Len(Fx$)-D%)
        X$ = Left$(X$,Instr(")",X$))
        Xl% = Len(X$)
        X$ = Del$(X$,Len(X$),1)

        If Operator(X$)

            Print "Parse "+X$+"..."

            Whileloop 5

                In%=Instr(Mid$("^*/+-",&Loop,1),X$)
                C%=&Loop

                While In%

                    A% = In%
                    X1! = Getbefore(X$,A%)
                    X2! = Getafter(X$,A%)

                    If Equ(C%,1)

                        Print "Potenz"
                        Erg! = X1! ^ X2!

                    Elseif Equ(C%,2)

                        Print "Mal"
                        Erg! = X1! * X2!

                    Elseif Equ(C%,3)

                        Print "Durch"
                        Erg! = X1! / X2!

                    Elseif Equ(C%,4)

                        Print "Plus"
                        Erg! = X1! + X2!

                    Else

                        Print "Minus"
                        Erg! = X1! - X2!

                    Endif

                    Y$ = Del$(X$,1,Y2%-1)
                    Z$ = If(Equ(Y1%,1),"",Left$(X$,Y1%-1))
                    X$ = Z$ + Str$(Erg!) + Y$
                    Print Str$(X1!) + "," + Str$(X2!) + "=" + Str$(Erg!)
                    Print "Neue Teilformel: "+X$
                    In% = Instr(Mid$("^*/+-",C%,1),X$)
                    Waitinput

                Wend

            Wend

        Endif

        Fx$ = Left$(Fx$,D%-1) + Str$(Erg!) + Right$(Fx$,Len(Fx$)-D%-Xl%)
        Print "Neue Formel: "+Fx$

    Wend

    Return Fx$

Endproc

Declare S$
Cls
S$ = "(((3+5)*2+3*(12+345))+12)"
Print "Formel: "+S$
Print "Ergebnis: "+Parsepan>s$)
Waitinput
End

well then in the pseudo-code understand:

Fx$ = (((3+5)*2+3*(12+345))+12)

(((3+5)*2+3*(12+345))+12)
........................^
D% = 25

(((3+5)*2+3*(12+345))+12)
............^
D% = 13

X$ = (12+345))+12)
X$ = (12+345)
X1% = 8
X$ = (12+345
A% = 4

X1! = GetBefore( (12+345, 4 ) ** is the so pseudo? Val() resolve Error from and supply 0
Y1% = 1
X1! = 0.0

X2! = GetAfter( (12+345, 4 )
Y2% = 8
X2! = 345.0
Erg! = 345.0

Y$ =
Z$ =
X$ = 345.0000

Print: 0.0000,345.0000=345.0000
Print: new Teilformel: 345.0000

Fx$ = (((3+5)*2+3*345.0000+12)
Print: new Formel: (((3+5)*2+3*345.0000+12)

(((3+5)*2+3*345.0000+12)
....................^ ** here missing now a schließende Klammer
...
... etc.


It can naturally his, that I there verhaspelt have. One Papiercomputer (so called these Herangehensweise) is naturally only so well How the executing The functions knows.

your supposition has incidentally confirm: größter Übeltäter is the GetBefore().

Best wishes
Michael Wodrich
 
Programmieren, das spannendste Detektivspiel der Welt.
02/09/06  
 




Jac
de
Lad
Erstmal thanks for trouble. with Papiercomputern can I somehow nothing begin what about me kommentiere always badly. yet have I but any Problems solve can. Hm, I probiers time with GetBefore with Neq(Instr(...),0), Perhaps helps the. I login me again!

Jac
 
Profan² 2.6 bis XProfan 11.1+XPSE+XPIA+XPRR (und irgendwann XIDE)
Core2Duo E8500/T2250, 8192/1024 MB, Radeon HD4850/Radeon XPress 1250, Vista64/XP
02/09/06  
 




Jac
de
Lad
Oh, damn. Have strain first found...I building first everything circa, what You already angekreidet have. already embarrassing wieviele Error You at a single blow find...but is too not yet ready!

Jac
 
Profan² 2.6 bis XProfan 11.1+XPSE+XPIA+XPRR (und irgendwann XIDE)
Core2Duo E8500/T2250, 8192/1024 MB, Radeon HD4850/Radeon XPress 1250, Vista64/XP
02/09/06  
 




Jac
de
Lad
Oh, damn. Have strain first found...I building first everything circa, what You already angekreidet have. already embarrassing wieviele Error You at a single blow find...but is too not yet ready!

Jac
 
Profan² 2.6 bis XProfan 11.1+XPSE+XPIA+XPRR (und irgendwann XIDE)
Core2Duo E8500/T2250, 8192/1024 MB, Radeon HD4850/Radeon XPress 1250, Vista64/XP
02/09/06  
 




Jac
de
Lad
Hello Michael!

thanks for large Help, I have any Error found and the Parser runs now with the 5 Grundrechenarten (naja, 4 Grundrechenarten plus Potenz) correct. alas incidentally: The procedure Operator determined only, whether it itself at übergebenen String solely circa a number or a Term deals. More not. Well, i'll the part now at the end develop...

has at all someone on it interest???

Jac
 
Profan² 2.6 bis XProfan 11.1+XPSE+XPIA+XPRR (und irgendwann XIDE)
Core2Duo E8500/T2250, 8192/1024 MB, Radeon HD4850/Radeon XPress 1250, Vista64/XP
02/09/06  
 



we've any interest at a Compute-function!
 
02/09/06  
 




Jac
de
Lad
Oh, hm...

Well I Have this afternoon etliche hours dran written. only unfortunately is me short before the end noticed, I negatives numbers none viewing have. means catch I now again from scratch on! I login me again!

Jac
 
Profan² 2.6 bis XProfan 11.1+XPSE+XPIA+XPRR (und irgendwann XIDE)
Core2Duo E8500/T2250, 8192/1024 MB, Radeon HD4850/Radeon XPress 1250, Vista64/XP
02/09/06  
 



Answer


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

637 Views

Untitledvor 0 min.
RudiB.04/15/20
Peter Max Müller05/18/18
Michael W.12/23/16
Julian Schmidt09/11/12

Themeninformationen

this Topic has 3 subscriber:

Jac de Lad (6x)
iF (1x)
Michael Wodrich (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie