78 lines
1.6 KiB
Plaintext
78 lines
1.6 KiB
Plaintext
module TrueTable {
|
|
Input "How many parameters:";N
|
|
if N<1 then exit
|
|
if N>26 then Restart
|
|
print "Use of variables:", @(19),
|
|
for i=1 to N
|
|
print " "+chr$(i+64);
|
|
next
|
|
print
|
|
print "Identifiers:", @(20), "NOT AND OR XOR TRUE FALSE"
|
|
print "Symbols:", @(20), "( )"
|
|
dim a(0 to N) as boolean
|
|
a(N)=true
|
|
input "boolean expression: ";E$
|
|
E$=ucase$(E$)
|
|
P$=E$
|
|
E$=replace$("TRUE", "___", E$)
|
|
E$=replace$("FALSE", "^^^", E$)
|
|
E$=replace$("AND", "%%%", E$)
|
|
E$=replace$("XOR", "???", E$)
|
|
E$=replace$("OR", "!!!", E$)
|
|
E$=replace$("NOT", "^^^", E$)
|
|
Z$=filter$(E$, "%?!^()_^")
|
|
try ok {
|
|
for i=0 to N-1
|
|
Z$=filter$(Z$, chr$(i+65))
|
|
if instr(E$,chr$(i+65))=0 then Error "Missing "+chr$(i+65)
|
|
E$=replace$(chr$(i+65), "[]("+i+")", E$)
|
|
next
|
|
}
|
|
if error or not ok then print "Error"+Error$ : restart
|
|
if trim$(Z$)<>"" then print "FOUND:";Z$;"ILLEGAL CHARACTERS": restart
|
|
E$=replace$("%%%","AND", E$)
|
|
E$=replace$("???", "XOR", E$)
|
|
E$=replace$( "!!!", "OR", E$)
|
|
E$=replace$("^^^", "NOT", E$)
|
|
E$=replace$("[]", "a", E$)
|
|
E$=replace$("___", "TRUE", E$)
|
|
E$=replace$("^^^", "FALSE", E$)
|
|
S$=""
|
|
H$=""
|
|
B$=""
|
|
for i=1 to N
|
|
H$+=" "+chr$(i+64)+" |"
|
|
B$+="-------+"
|
|
next
|
|
B$+=string$("-",len(P$))
|
|
H$+=P$
|
|
print H$
|
|
S$=H$+{
|
|
}
|
|
try ok {
|
|
do L$=""
|
|
for i=0 to N-1
|
|
L$+=format$(" {0:5} |", a(i))
|
|
next
|
|
L$+=" "+Str$(Eval(E$))
|
|
print B$
|
|
print L$
|
|
S$+=B$+{
|
|
}+L$+{
|
|
}
|
|
when @PlayNext()
|
|
clipboard S$
|
|
}
|
|
if error or not ok then print "Error"+Error$ : restart
|
|
End
|
|
function PlayNext()
|
|
local i
|
|
for i=0 to N
|
|
a(i)=not a(i)
|
|
if a(i) then exit for
|
|
next
|
|
=N>=i
|
|
end function
|
|
}
|
|
TrueTable
|