| |
|
|
 Julian Schmidt | Salut, j'ai mich la fois à einem kleinen Parser probiert. Evtl. sommes dans cette allerdings encore un paire kleinere faute drin.
Vlt. peut son mir aider. KompilierenMarqueSéparationWindowTitle "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 trop marcher. seulement chez dem Klammern!?
LG
Julian |
|
|
| |
|
|
|
 | |
|
| |
|
|
|
 Julian Schmidt | Jo, déjà gesehen. Hilft mir mais pas wirklich! je suis plutôt sur Fehlersuche et serait volontiers simple la fois quelques Fälle de euch écouter wohin mon calculette versagt et peut-être. une Strategie zur Solution des Problems.
Evtl. habe je oui sogar quelques Rechenregeln sauf huit gelassen, quelle important wären!?? Evtl. aussi Anregungen zum Programmier-Style, et comment on gewisse Dinge kürzen pourrait. |
|
|
| |
|
|
|
 | Gibt oui erstmal seulement Klammer avant Punkt et Punkt avant Strich umzusetzen.
Funktioniert cela car bereits correct?
Tricky ist plutôt quelque chose comme comment -5 + -1 |
|
|
| |
|
|
|
 Julian Schmidt | Klammer avant Potenz avant Punkt avant Strich funktioniert bereits zum Großenteil. seulement gibt es chez certain Klammerabfolgen malheureusement encore Probleme. Etwa chez "5+(30*(4/2)+10)". peux es momentan selbst avec TraceModus pas entier nachvollziehen. Scheint irgendwie avec dem Geteilt dedans qui Klammer zusammenzuhängen. avec la fois funktioniert es entier hervorragend!
comment würdest du, qui Geschichte avec dem negativen payons angehen? |
|
|
| |
|
|
|
 | cela hängt très en ab quoi oui c'est ca Dein Parser später la fois alles peut soll -
cet information fehlt mir z.B. .
je serait wohl comment dans xpse mise en œuvre toujours une Parser herstellen qui possible
flexibel ist et plan égal quelle Argumente de à gauche à droite parsen et auflösen
peux. si Du seulement bisl Matheformeln parsen vouloir ensuite peux pour cela Minus-
Vorzeichen simple Ausnahmen/ Erkennungen programmieren. Hat zwar rien avec
dem Thema trop 1faire mais tu peux aussi XProfan selbst verwenden comment z.B. dans
XP-Script [...] (quoi mais seulement jusqu'à XP vollständig korrekt funktioniert). |
|
|
| |
|
|
|
 Julian Schmidt | peux du nochmal konkret etwa trop, comment on am Besten une flexiblen Parser baut et zur Ausnahme\Erkennung einer negativen numéro dire? |
|
|
| |
|
|
|
 | j'écrivais oui bereits:
cela hängt très en ab quoi oui c'est ca Dein Parser später la fois alles peut soll -
cet information fehlt mir z.B. . |
|
|
| |
|
|
|
 Julian Schmidt | Konkret +,-,*,\,^ et den richtigen Umgang avec Klammern, Minuszahlen. Evtl. Wurzel bzw. Wurzel_n et Logarithme. |
|
|
| |
|
|
|
 Julian Schmidt | comment würdest du den une Parser possible flexibel écrivons? comment programmiert on am besten une "Minus-Vorzeichen Ausnahmen/ Erkennungen"? |
|
|
| |
|
|
|
 | Erstmal brauchst paire Helferfunktionen.
Z.B. une Funktion parse écrivons qui z.B. 2 Longs comme Param erhält:
SpeicherAddr,BytesToParse
et le nombre qui geparsten Bytes zurückliefert.
Wenns un Ansi-Parser volonté soll ensuite ist BytesToParse est un 256 Byte großer
grenier - simple Faible prendre. y sommes alle Bytes sur True qui qui Funktion
parse emmener soll. Pratiquement.
byte BytesToParse,65=1,1,1,1,1
womit qui Chars A;B;C;D;E gemeint wären -
alors qui Funktion seulement so longtemps ließt comment cet Chars auftreten.
Ist arrêt wohl cela Schnellste là solch Funktion parse seulement gezielte/ directe Speicherzugriffe
braucht afin de ermitteln quoi à l'attaque ist.
quasi tandis que byte(BytesToParse,byte(SpeicherAddr,pos++)) statt 17 ifs et instrs -
alors komplett sans Instr et herumsucherei.
si cela erste marque une Klammer ist hat qui Funktion z.B. aussi qui particularité,
qui aufgehenden Klammern trop zählen et ensuite le nombre gelesener Bytes
zurückzuliefern si, le nombre qui Klammern de 1 sur 0 springt - so peux
simple qui Klammern ensuite wegoperieren là toujours cela erste et cela dernier
marque Klammern sommes si cela erste marque une Klammer ist.
ca ist ensuite meist 1 Argument cela on dans einer extra liste enlever
peux pour späteres weiteres décomposer.
fais aus:
1+(10*20)+5
Listboxeinträge:
add 1 add 10*20 add 5  et dans einem weitere Pass:
add 1 add tmp1,10 mul tmp1,20 add tmp1 add 5 
quasi auflösen jusqu'à es seulement encore Operationen gibt qui Du dans qui liste comme "kann
je sans weitere OP ausrechnen" markiert la hâte.
Pour diesem procéder peux beliebig-komplexe et mehrzeilige Argumente-
Ketten auflösen. |
|
|
| |
|
|
|
 Julian Schmidt | hmmmm...je muss je honnête gestehen j'ai seulement gare verstanden.
comment würdest du une Parser possible flexibel, sous Verwendung de (partie)string-Funktionen, écrivons? |
|
|
| |
|
|