Solved LeetCode program · 835 of 1,000
#1106 · Parsing A Boolean Expression
Original English source
Keep a shared source as empty text. Place "|(&(t,f,t),!(t))" into source. Keep a shared cursor of 0. Keep a shared value of 0.
To parse. The index is cursor. The symbol is the slice of source from index to index plus 1. If symbol matches "t", set value to 1, add 1 to cursor, return. If symbol matches "f", set value to 0, add 1 to cursor, return. If symbol matches "!", Negate. If symbol matches "&", Conjoin. If symbol matches "|", Disjoin.
To negate. Add 2 to cursor. Parse. The inside is value. Add 1 to cursor. Set value to 1 minus inside.
To conjoin. Add 2 to cursor. The total is 1. The index is cursor. The symbol is the slice of source from index to index plus 1.
Repeat while symbol does not match ")".
Parse. Set total to total times value. The index is cursor. The symbol is the slice of source from index to index plus 1. If symbol matches ",", add 1 to cursor. If symbol matches ")", add 1 to cursor. Set value to total.
To disjoin. Add 2 to cursor. The total is 0. The index is cursor. The symbol is the slice of source from index to index plus 1.
Repeat while symbol does not match ")".
Parse. Increase total by value. The index is cursor. The symbol is the slice of source from index to index plus 1. If symbol matches ",", add 1 to cursor. If symbol matches ")", add 1 to cursor. Set value to total.
Parse. If value is 1, show true, otherwise show false.
Expected stdout
false