Next / Previous / Contents / Shipman's homepage

7. main()

tracecase
# - - - - -   m a i n

def main():
    '''Main program.

      [ if sys.stdin contains a valid truth table ->
          I
        else ->
          sys.stdout  +:=  error message(s) ]
    '''

First we read all the lines of the input, then we pass the entire list of lines to the constructor for Section 9, “class Truths.

tracecase
    #-- 1
    # [ sys.stdin  :=  sys.stdin advanced to end of file
    #   rawLines  :=  list of lines from sys.stdin ]
    rawLines = sys.stdin.readlines()

    #-- 2
    # [ if rawLines is a valid truth table ->
    #     truths  :=  a Truths instance representing rawLines
    #   else ->
    #     sys.stdout  +:=  error message(s)
    #     stop execution ]
    try:
        truths = Truths(rawLines)
    except ValueError as x:
        fatal("Invalid input: {0}".format(str(x)))

The method Section 12, “Truths.check(): Generate error messages” returns a list of error strings.

tracecase
    #-- 3
    # [ sys.stdout  +:=  error messages from truths ]
    for message in truths.check():
        print(message)