Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Tcl Online

puts "Truth Table based Gate Level Simulator"
# boolean equation provided as input and displays it
puts -nonewline "Enter a boolean expression: "
flush stdout
set exp [gets stdin]
puts $exp
set variables [lsort -unique [regexp -inline -all {\$\w+} $exp]]
set length [llength $variables]
# differentiating among the variables as hey can be present number of times
set command [list format [string repeat "%s\t" $length]%s]
append command " {*}\[[list subst $variables]\] \[[list expr $exp]\]" 
set command "puts \[$command\]"
#calculates the value for each input combinations 
foreach v [lreverse $variables] {
set command [list foreach [string range $v 1 end] {0 1} $command]
}
#displays the output
puts " "
puts [join $variables \t]\tResult
apply [list {} $command]

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.