This class is used to parse any expression which contain boolean variables. Input String can be in the form of logical operators which can be parsed to Gates by this class. This is also used to obtain the truth tables”
Logical Operator form: Function takes only equation as an input. Gates Form: Needs The variable inputs also as an argument. Examples:
>>> from BinPy import *
>>> expr = Expr('A & B | C')
>>> expr.parse()
'AND(OR(C,B),A)'
>>> expr.truthTable()
A B C O
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
>>> expr = Expr('AND(NOT(A), B)', 'A', 'B')
>>> expr.parse()
'AND(NOT(A),B)'
>>> expr.truthTable()
A B O
0 0 0
0 1 1
1 0 0
1 1 0
Returns the index of the opposite matching brace for the brace at string[position]