
(define (log-error err token)
  (newline)
  (display "*** ERROR ")
  (case err
    ((REST_OF_PROGRAM_IGNORED)
      (display "rest of program ignored"))
    ((EXPECT_TOKEN)
      (display token)
      (display " expected"))
    ((BAD_STATEMENT)
      (display "bad statement ")
      (display token))
    ((CONTROL_VAR_MISMATCH)
      (display "control and increment var not the same"))
    ((EXPECTING_INCR_DECR)
      (display "expecting ++ or --"))
    ((NUMBER_EXPECTED)
      (display "number expected instead of: ")
      (display token))
    ((MAX_ALLOWED_FORMAL_PARAMETERS)
      (display "maximum number of allowed formal parameters exceeded"))
    ((MISMATCHED_PARENS)
      (display "mismatched parentheses"))
    ((MISMATCHED_PARENS_OR_MISSING_COMMA)
      (display "mismatched parentheses or misplaced comma"))
    ((STACK_UNDERFLOW)
      (display "stack underflow"))
    ((UNDEFINED_CONSTANT)
      (display "undefined constant: ")
      (display token))
    ((UNDEFINED_IDENTIFIER)
      (display "undefined identifier: ")
      (display token))
    ((STRING_EXPECTED)
      (display "string expected: ")
      (display token)))
  (newline))

(define (expect expected-token)
  (let
    ((token (get-token)))
    (if (not (eq? token expected-token))
      (log-error 'EXPECT_TOKEN expected-token))))
