| |
|
|
Julian Schmidt | ¡Hola, Yo mich veces a una pequeño Parser probiert. Evtl. son en esta allerdings todavía unos pocos kleinere Fehler drin.
Vlt. könnt ihr me helfen. KompilierenMarcaSeparaciónWindowTitle "Simple Parser"
Windowstyle 24
Window (%maxx-280)\2,(%maxy-210)\2 - 280,210
Var ed_calc&=Create("Edit",%hwnd,"5+(30*10)",10,10,width(%hwnd)-20,20)
Var lb_calc&=Create("ListBox", %hwnd, 0, 10, 40, width(%hwnd)-20, 100)
Var bt_calc&=Create("Button",%hwnd,"Ausrechnen",10,150,width(%hwnd)-20,25)
Declare calc$,pos_z1%
WhileNot iskey(27)
Waitinput 300
If getfocus(bt_calc&) or iskey(13)
ClearList lb_calc&
calc$=Translate$(Translate$(GetText$(ed_calc&),",",".")," ","")
Addstring(lb_calc&,calc$)
If (InStr(")",calc$)<>0) and (InStr("(",calc$)<>0)
while (InStr(")",calc$)<>0) and (InStr("(",calc$)<>0)
whileloop InStr(")",calc$),1,-1
pos_z1%=&loop
case (Mid$(calc$,pos_z1%,1)="(") : break
Endwhile
calc$=Init_Parse(Mid$(calc$,pos_z1%+1,InStr(")",calc$)-(pos_z1%+1)),Mid$(calc$,1,pos_z1%-1),Mid$(calc$,InStr(")",calc$)+1,Len(calc$)-InStr(")",calc$)))
Endwhile
Else
calc$=Translate$(Translate$(calc$,")",""),"(","")
Endif
Init_Parse(calc$)
Setfocus(ed_calc&)
Endif
EndWhile
Proc Init_Parse
Parameters math$, str1$, str2$
WhileNot iskey(27)
Case GetString$(lb_calc&,Getcount(lb_calc&)-1)<>str1$+math$+str2$ : Addstring(lb_calc&,str1$+math$+str2$)
If (InStr("^",math$)<>0)
Parse("^")
ElseIf (InStr("*",math$)<>0)
Parse("*")
ElseIf (InStr("+",math$)<>0)
Parse("+")
ElseIf (InStr("-",math$)<>0)
Parse("-")
ElseIf (InStr("\",math$)<>0) or (InStr("/",math$)<>0)
Parse("\")
Else
Settext ed_calc&,math$
break
EndIf
EndWhile
Return str1$+math$+str2$
EndProc
Proc Parse
Parameters op$
Declare pos_z2%, z1$,z2$
Var pos_op%=InStr(op$,math$)
Whileloop pos_op%-1,0,-1
If (Mid$(math$,&loop,1)="+") or (Mid$(math$,&loop,1)="-") or (Mid$(math$,&loop,1)="\") or (Mid$(math$,&loop,1)="/") or (Mid$(math$,&loop,1)="*") or (Mid$(math$,&loop,1)="^") or (trim$(Mid$(math$,&loop,1))="")
z1$=Mid$(math$,&loop+1,pos_op%-(&loop+1))
pos_z1%=&loop+1
break
Endif
EndWhile
Whileloop pos_op%+1,Len(math$)+1,1
If (Mid$(math$,&loop,1)="+") or (Mid$(math$,&loop,1)="-") or (Mid$(math$,&loop,1)="\") or (Mid$(math$,&loop,1)="/") or (Mid$(math$,&loop,1)="*") or (Mid$(math$,&loop,1)="^") or (trim$(Mid$(math$,&loop,1))="")
z2$=Mid$(math$,pos_op%+1,&loop-(pos_op%+1))
pos_z2%=&loop
break
Endif
EndWhile
If ((op$="\") and (z2$="0"))
math$="Division durch NULL!"
Else
Var erg$=Str$(If(op$="+",Val(z1$)+Val(z2$),If(op$="-",Val(z1$)-Val(z2$),If(op$="*",Val(z1$)*Val(z2$),If(op$="\",Val(z1$)/Val(z2$),If(op$="^",Val(z1$)^Val(z2$),"Error"))))))
math$=Mid$(math$,1,pos_z1%-1)+erg$+Mid$(math$,pos_z2%,(Len(math$)+1)-pos_z2%)
Settext ed_calc&,math$
Endif
ENDPROC
Scheint soweit allerdings a trabajo. Nur en el Klammern!?
LG
Julian |
|
|
| |
|
|
|
| |
|
| |
|
|
|
Julian Schmidt | Jo, ya gesehen. Hilft me pero no wirklich! Yo bin más en Fehlersuche y sería gerne simplemente veces algunos Fälle de euch hören wo mein Taschenrechner versagt y evtl. una Strategie a Solución des Problems.
Evtl. Yo sí incluso algunos Rechenregeln außer Acht gelassen, welche wichtig wären!?? Evtl. auch Sugerencias para Programmier-Style, y cómo gewisse Dinge kürzen podría. |
|
|
| |
|
|
|
| Gibt sí primero sólo Klammer antes Punkt y Punkt antes Strich umzusetzen.
Funktioniert el porque ya fehlerfrei?
Tricky es más algo como como -5 + -1 |
|
|
| |
|
|
|
Julian Schmidt | Klammer antes Potenz antes Punkt antes Strich funktioniert ya para Großenteil. Nur hay en cierto Klammerabfolgen desafortunadamente todavía Problemas. Etwa en "5+(30*(4/2)+10)". Kann lo momentan incluso con TraceModus no bastante nachvollziehen. Scheint irgendwie con el Geteilt innerhalb el Klammer zusammenzuhängen. Mit Tiempo funktioniert lo bastante hervorragend!
Como würdest du, el Geschichte con el negativen Pagar angehen? |
|
|
| |
|
|
|
| Das hängt muy su de ¿qué es exactamente Su Parser später veces alles puede se -
esta Information fehlt me z.B. .
Yo sería wohl como en xpse umgesetzt siempre una Parser herstellen el möglichst
flexibel es y eben egal welche Argumente de links después de rechts parsen y auflösen
kann. Si usted sólo bisl Matheformeln parsen möchtest entonces kannst para el Minus-
Vorzeichen simplemente Ausnahmen/ Erkennungen programa. Sombrero zwar nichts con
el Thema a tun aber Usted puede auch XProfan incluso uso como z.B. en
XP-Script [...] (qué aber sólo a XP vollständig korrekt funktioniert). |
|
|
| |
|
|
|
Julian Schmidt | ¿Puede du otra vez konkret etwa a, cómo al Besten una flexiblen Parser baut y a Excepción\Erkennung uno negativen Zahl sagen? |
|
|
| |
|
|
|
| Yo schrieb sí ya:
Das hängt muy su de ¿qué es exactamente Su Parser später veces alles puede se -
esta Information fehlt me z.B. . |
|
|
| |
|
|
|
Julian Schmidt | Konkret +,-,*,\,^ y el richtigen Umgang con Klammern, Minuszahlen. Evtl. Wurzel o. Wurzel_n y Logaritmo. |
|
|
| |
|
|
|
Julian Schmidt | Como würdest du el una Parser möglichst flexibel escribir? Como programmiert uno al besten una "Minus-Vorzeichen Ausnahmen/ Erkennungen"? |
|
|
| |
|
|
|
| Erstmal necesidad pocos Helferfunktionen.
Z.B. una Función parse escribir el z.B. 2 Longs como Param erhält:
SpeicherAddr,BytesToParse
y el número el geparsten Bytes zurückliefert.
Wenns una Ansi-Parser voluntad se entonces BytesToParse es una 256 Byte großer
Speicher - simplemente Dim nehmen. Darin son todos Bytes en True el el Función
parse mitnehmen se. Quasi.
byte BytesToParse,65=1,1,1,1,1
womit el Chars A;B;C;D;E gemeint wären -
Así que el Función sólo así largo ließt como esta Chars auftreten.
Ist sólo wohl el Schnellste como solch Función parse sólo gezielte/ direkte Speicherzugriffe
braucht en a ermitteln qué los es.
quasi mientras que byte(BytesToParse,byte(SpeicherAddr,pos++)) en lugar de 17 ifs y instrs -
also komplett sin Instr y herumsucherei.
Si el erste Signo una Klammer es ha el Función z.B. auch el Eigenheit,
el aufgehenden Klammern a zählen y entonces el número gelesener Bytes
zurückzuliefern si, el número el Klammern de 1 en 0 springt - así kannst
simplemente el Klammern entonces wegoperieren como siempre el erste y el letzte
Signo Klammern son si el erste Signo una Klammer es.
Dies es entonces meist 1 Argument el uno en uno extra Liste ablegen
kann para späteres weiteres zerlegen.
Mache de:
1+(10*20)+5
Listboxeinträge:
add 1 add 10*20 add 5 y una weitere Pass:
add 1 add tmp1,10 mul tmp1,20 add tmp1 add 5
quasi auflösen a lo sólo todavía Operationen son el Usted en el Liste como "kann
Yo sin weitere OP ausrechnen" markiert hast.
Nach diesem Verfahren kannst cualquier-komplexe y mehrzeilige Argumente-
Ketten auflösen. |
|
|
| |
|
|
|
Julian Schmidt | hmmmm...Yo muss Yo ehrlich gestehen Yo sólo Bahnhof verstanden.
Como würdest du una Parser möglichst flexibel, bajo Verwendung de (Teil)cadena-Características, escribir? |
|
|
| |
|
|