contestada

, someone who is good at programming can write me a program in C or Python to check if a sentence is well formatted or not? And if it is not to show and where is the error?
Example of a well-formed sentence: ((P -> Q) ^ (Q ^ P))
(it's logical sentences from computational logic)