Example 29: (a AND b) OR (NOT c AND d)
- Read ‘(‘ and push onto stack: Stack = (
- Read ‘a’ and add to output: Output = a
- Read ‘AND’ and push onto stack: Stack = (, AND
- Read ‘b’ and add to output: Output = ab
- Read ‘)’ and pop operators until ‘(‘: Output = abAND, Stack =
- Read ‘OR’ and push onto stack: Stack = OR
- Read ‘(‘ and push onto stack: Stack = OR, (
- Read ‘NOT’ and push onto stack: Stack = OR, (, NOT
- Read ‘c’ and add to output: Output = abANDc
- Read ‘AND’ and push onto stack: Stack = OR, (, NOT, AND
- Read ‘d’ and add to output: Output = abANDcNOTd
- Read ‘)’ and pop operators until ‘(‘: Output = abANDcNOTdAND, Stack = OR
- Finish by popping operators from stack to output: Output = abANDcNOTdANDOR
Final Result: abANDcNOTdANDOR
Example 30: NOT (a AND (b OR c) AND d)
- Read ‘NOT’ and push onto stack: Stack = NOT
- Read ‘(‘ and push onto stack: Stack = NOT, (
- Read ‘a’ and add to output: Output = a
- Read ‘AND’ and push onto stack: Stack = NOT, (, AND
- Read ‘(‘ and push onto stack: Stack = NOT, (, AND, (
- Read ‘b’ and add to output: Output = ab
- Read ‘OR’ and push onto stack: Stack = NOT, (, AND, (, OR
- Read ‘c’ and add to output: Output = abc
- Read ‘)’ and pop operators until ‘(‘: Output = abcOR, Stack = NOT, (, AND
- Read ‘AND’ and push onto stack: Stack = NOT, (, AND, AND
- Read ‘d’ and add to output: Output = abcORd
- Read ‘)’ and pop operators until ‘(‘: Output = abcORdANDAND, Stack = NOT
- Finish by popping operators from stack to output: Output = abcORdANDANDNOT
Final Result: abcORdANDANDNOT
Example 31: (p AND q) OR NOT (r AND s OR t)
- Repeat steps for inside expression (p AND q): Output = pqAND
- Read ‘OR’ and push onto stack: Stack = OR
- Read ‘NOT’ and push onto stack: Stack = OR, NOT
- Read ‘(‘ and push onto stack: Stack = OR, NOT, (
- Read ‘r’ and add to output: Output = pqANDr
- Read ‘AND’ and push onto stack: Stack = OR, NOT, (, AND
- Read ‘s’ and add to output: Output = pqANDrs
- Read ‘OR’ and push onto stack: Stack = OR, NOT, (, AND, OR
- Read ‘t’ and add to output: Output = pqANDrst
- Read ‘)’ and pop operators until ‘(‘: Output = pqANDrstORAND, Stack = OR, NOT
- Finish by popping operators from stack to output: Output = pqANDrstORANDNOTOR
Final Result: pqANDrstORANDNOTOR
Example 32: (a OR b) AND (NOT c OR d AND e) OR f
- Repeat steps for inside expression (a OR b): Output = abOR
- Read ‘AND’ and push onto stack: Stack = AND
- Read ‘(‘ and push onto stack: Stack = AND, (
- Read ‘NOT’ and push onto stack: Stack = AND, (, NOT
- Read ‘c’ and add to output: Output = abORc
- Read ‘OR’ and push onto stack: Stack = AND, (, NOT, OR
- Read ‘d’ and add to output: Output = abORcNOTd
- Read ‘AND’ and push onto stack: Stack = AND, (, NOT, OR, AND