Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,56 @@
|
|||
Module Rpn_2_Infix {
|
||||
Rem Form 80,60
|
||||
function rpn_to_infix$(a$) {
|
||||
def m=0
|
||||
inventory precendence="-":=2,"+":=2,"*":=3,"/":=3,"^":=4
|
||||
dim token$()
|
||||
token$()=piece$(a$," ")
|
||||
l=len(token$())
|
||||
dim type(l)=0, right(l)=0, infix$(l)
|
||||
infix=-1
|
||||
for i=0 to l-1
|
||||
if exist(precendence, token$(i)) then
|
||||
type(i)=precendence(token$(i))
|
||||
if type(i)=4 then right(i)=-1
|
||||
end if
|
||||
if type(i)=0 then
|
||||
infix++
|
||||
infix$(infix)=token$(i)
|
||||
type(infix)=100
|
||||
else
|
||||
if right(i) then
|
||||
if type(infix)<type(i) then infix$(infix)="("+infix$(infix)+")"
|
||||
if type(infix-1)<100 then infix$(infix-1)="("+infix$(infix-1)+")"
|
||||
infix$(infix-1)=infix$(infix-1)+token$(i)+infix$(infix)
|
||||
else
|
||||
if type(infix)<type(i) then infix$(infix)="("+infix$(infix)+")"
|
||||
if type(infix-1)<type(i) then
|
||||
infix$(infix-1)="("+infix$(infix-1)+")"+token$(i)+infix$(infix)
|
||||
else
|
||||
infix$(infix-1)=infix$(infix-1)+token$(i)+infix$(infix)
|
||||
end if
|
||||
end if
|
||||
type(infix-1)=type(i)
|
||||
infix--
|
||||
end if
|
||||
inf=each(infix$(),1, infix+1)
|
||||
while inf
|
||||
export$<=token$(i)+" ["+str$(inf^,"")+"] "+ array$(inf)+{
|
||||
}
|
||||
token$(i)=" "
|
||||
end while
|
||||
next i
|
||||
=infix$(0)
|
||||
}
|
||||
Global export$
|
||||
document export$
|
||||
example1=rpn_to_infix$("3 4 2 * 1 5 - 2 3 ^ ^ / +")="3+4*2/(1-5)^2^3"
|
||||
example2=rpn_to_infix$("1 2 + 3 4 + ^ 5 6 + ^")="((1+2)^(3+4))^(5+6)"
|
||||
\\ a test from Phix example
|
||||
example3=rpn_to_infix$("moon stars mud + * fire soup * ^")="(moon*(stars+mud))^(fire*soup)"
|
||||
Print example1, example2, example3
|
||||
Rem Print #-2, Export$
|
||||
ClipBoard Export$
|
||||
|
||||
}
|
||||
Rpn_2_Infix
|
||||
Loading…
Add table
Add a link
Reference in a new issue