truth_table <- function(x) {
  vars <- unique(unlist(strsplit(x, "[^a-zA-Z]+")))
  vars <- vars[vars!= ""]
  perm <- expand.grid(rep(list(c(FALSE, TRUE)), length(vars)))
  names(perm) <- vars
  perm[ , x] <- with(perm, eval(parse(text = x)))
  perm
}

"%^%" <- xor 

truth_table("!A") 




truth_table("A | B") 






truth_table("A & B") 






truth_table("A%^% B") 






truth_table("S | (T%^% U)") 










truth_table("A%^% (B%^% (C%^% D))")