Commit Graph

14 Commits

Author SHA1 Message Date
Glen Whitney 6534aec2fd Add type predicate
The main new finction is is(), which tests the type of a value. There
  are also constants for each of the possible token types, and one new
  conversion: number(), which converts a value into the most appropriate number
  type. This change also reuses the functions in scanner.h for exracting ints,
  floats, and identifiers from strings, rather than either rewriting the
  functionality elsewhere, or using the general-purpose scan when only one
  token type was of interest.
2019-08-27 23:30:02 -07:00
Glen Whitney 892fdcdb75 Add BOOL token_type, macros, and boolean operators
For clarity, it is valuable for the results of comparisons to show as "true"
  and "false" rather than "1" and "0". This change implements a BOOL type
  to facilitate that. Since we want logical operators to short-circuit, this
  change also obliges the introduction of macros, which are just like functions
  except their arguments are not evaluated before control is passed to the
  routine implementing the macro.
2019-08-26 23:56:19 -07:00
Glen Whitney 7e0ba7370d Add functions for unit displacements in the siz cardinal directions
This change is the "easy" part of #64, but to reduce the amount of duplicated
   code, this change also modifies the internals of implementing a function.
   The function identifier is now passed to the implementation as well, allowing
   many implementations of similar functions to be collapsed more easily.
2019-08-25 23:19:34 -07:00
Glen Whitney 9670e8b4a1 Print parse trees with infix notation
Fixes #62.
2019-08-24 15:17:35 -07:00
Glen Whitney 96079b210e Make tpa the default file format for Teapot
There turned out to be one blocking technical issue for full adpotion of
  tpa format, and that was the fact that the printed representation of
  floating values inside the tpa file might not reproduce the same double
  when read. This change therefore introduces the "hexact" floating point
  format, based on the the %La format string, which produces a hex
  representation with exact round trips. While working on this, it was
  convenient to add a new representation "compact" which is basically the
  shorter of decimal and scientific representations, without trailing zeros.
  This is now the default float format, but of course one can select decimal
  or scientific formats to restore prior appearance. However, full-precision
  compact format is now the (only) format for editing cell contents, as it
  is accurate and efficient. Of course you can enter floating point values
  in any format you like when typing in a formula.

  The addition of several new floating point options overloaded the menus
  in terminal teapot, so this change also revamps those menus slightly,
  including eliminating the unused MenuChoice struct, and just specifying menus
  with an array of strings.

  Closes #63.
2019-08-24 09:58:46 -07:00
Glen Whitney 364ef2c0ea Streamline internals of teapot
The primary change is to add a “funcall” token, so that an entire expression
  can be encapsulated as a single token. This change is used to allow a cell to
  include simply a selection of appropriate semantic tokens. I.e., the content
  and iterative content are now each a single token like the value and the
  result value. Token vectors are used only as intermediate results in scanning
  and parsing.

  Not this means the cells are now in effect storing parse trees, so
  computation should be slightly faster and future extensions (like #56) should
  be facilitated.

  This commit also takes the opportunity while internals are being altered to
  add another token to a cell for future use for computed attributes, cf #22,
  and to change the internal numerical values from double and ints to long
  doubles and long longs. However, the change attempts to encapsulate that
  choice so it would be easy to change back or change to another representation.

  Note that these changes break savexdr(), as the internal binary format of
  a cell is now different. Rather than reimplement it, it is deprecated as
  the world does not need another binary spreadsheet format. Hence, the
  ascii format for teapot spreadsheets becomes the primary file format.
  Loading of old xdr files is still supported for backward compatibility.

  Closes #59.

  Also along the way, various other slight fixes and enhancements crept in,
  a partial but probably not exhaustive list of which follows:

  Fixes #31.

  Further revisions and improvements to documentation.

  Make the approximate comparison of floating point values scale more
  accurately with the size of the doubles being compared.

  Further extensions of absolute and relative cell addressing.

  Addition of (circle constant) tau function/constant.

  Modified string conversion to simply use internal printing routines, and
  to take "scientific" and "decimal" keywords.

  Allowed n() function to take a list of values, or just a single location
  defaulting to the current location.

  Added floor, ceil, trunc, and round functions, and allowed them to be
  keywords controlling the int() integer conversion function as well.

  Allowed substr() to drop its last argument to go to the end of the string.

  Provided an enum of built-in functions to preserve legacy function
  identifiers, allowing the large table inside func.c to be reorganized
  in a clearer fashion.

  Added additional annotation of properties of the built-in functions,
  including precedence.

  All operators are now also accessible as built-in functions.

  Made precedence of unary - lower than ^ to match python.

  Avoided inadvertently using FLTK @symbol abbreviations for formulas with
  "@" in them.
2019-08-23 12:12:06 -07:00
Glen Whitney a56efa0c91 Prepare for parsing expressions into parse trees
Prior to this change, every evaluation re-parses the expression. The
  intermediate form as a parse tree is never stored anywhere. This change
  adds a new token type, FUNCALL, which acts as a node in a parse tree, and
  adds an (untested) evaluation method which returns the unevaluated parse tree
  as opposed to evaluating as it goes.

  This is preparation for a following step in which rather than storing a token
  sequence for each variety of content, teapot will store a single token
  representing the parse tree, allowing for quicker evaluation when the time
  comes; no actual parsing will have to occur on evaluation.
2019-08-05 16:45:04 -04:00
Glen Whitney 26ea0e05b3 Extend sum() to cover the case of just adding up all of its arguments.
Also a small amount of preparation of storing parse trees instead of
  linear sequences of tokens got mixed in here, namely a new type of
  token called a "FUNCALL".
2019-08-03 16:29:00 -04:00
Glen Whitney 341b12ba04 Implement a relative reference robust to source and reference moving
The new function is X(SRC,REF), which briefly for a cell in the neighborhood
   of REF returns the corresponding cell in the neighborhood in SRC. For
   further details, see the updated documention.

   In developing and documenting this function, I refined some of the
   existing error messages (e.g. showing the coordinates when there is an
   attempt to obtain a cell with a negative coordinate) and improved the
   error propagation to increase the chance that the innermost error will
   percolate to the top level.
2019-07-30 15:07:54 -04:00
Glen Whitney ab1a2fbb5a Fix relative addressing 2019-07-29 14:33:47 -04:00
Glen Whitney b3ea9f7ad9 Add relative address and at functions 2019-07-29 14:14:36 -04:00
Glen Whitney a5bf64b061 Add bitwise logical functions 2019-07-29 13:22:15 -04:00
Glen Whitney 1114df2e13 Extend max/min to cover an explicit list of values. 2019-07-29 12:42:51 -04:00
Glen Whitney ea230efc23 Move source code into subdirectory
Also removed a stray copy of the automatically generated config.h which
  had somehow gotten into the distribution. Closes #36.
2019-07-27 01:35:44 -04:00