README 974 B

123456789101112131415161718192021222324252627282930
  1. A slightly more powerful calculator that supports variables,
  2. plus some scientific functions like log(), sqr(), sin() etc.
  3. Most notably, this example demonstrates error handling.
  4. If/when one of your rule handlers comes across a condition
  5. which constitutes an error, but which the parser doesn't or can't
  6. pick up (eg division by zero), the handler should do:
  7. return self.error("string-describing-the-error")
  8. This will cause the parser to go into error handling mode.
  9. Also, your rules can pick up errors, by using the magic
  10. target name 'error'. Within error handling code, the
  11. 'lasterror' attribute of the parser object will be a
  12. 3-tuple:
  13. (line-num, msg, near-token)
  14. where:
  15. - 'line-num' is the input line at which the error (most likely)
  16. occured,
  17. - 'msg' is the error message text (supplied by either your own
  18. prior 'self.error(somestring)' call, or by the parser itself
  19. - 'near-token' is a string, the input token which triggered the
  20. error condition