2019-07-22 20:32:33 +00:00
|
|
|
/* #includes */ /*{{{C}}}*//*{{{*/
|
|
|
|
#ifndef NO_POSIX_SOURCE
|
|
|
|
#undef _POSIX_SOURCE
|
|
|
|
#define _POSIX_SOURCE 1
|
|
|
|
#undef _POSIX_C_SOURCE
|
|
|
|
#define _POSIX_C_SOURCE 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DMALLOC
|
|
|
|
#include "dmalloc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
extern double strtod(const char *nptr, char **endptr); /* SunOS 4 hack */
|
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 19:12:06 +00:00
|
|
|
extern long double strtold(const char *nptr, char **endptr); /* SunOS 4 hack */
|
2019-07-22 20:32:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "default.h"
|
|
|
|
#include "func.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "scanner.h"
|
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
/* charstring -- match quoted string and return token */ /*{{{*/
|
2019-08-28 06:30:02 +00:00
|
|
|
static Token *charstring(char **s)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-08-28 06:30:02 +00:00
|
|
|
char *r;
|
2019-07-22 20:32:33 +00:00
|
|
|
|
2019-08-28 06:30:02 +00:00
|
|
|
r = *s;
|
2019-07-22 20:32:33 +00:00
|
|
|
if (**s=='"')
|
|
|
|
{
|
|
|
|
++(*s);
|
|
|
|
while (**s!='\0' && **s!='"') if (**s=='\\' && *((*s)+1)!='\0') (*s)+=2; else ++(*s);
|
|
|
|
if (**s=='\0') { *s=r; return 0; }
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Token *n;
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
++(*s);
|
|
|
|
n=malloc(sizeof(Token));
|
|
|
|
n->type=STRING;
|
|
|
|
t=n->u.string=malloc((size_t)(*s-r));
|
|
|
|
/* Clean string of quotes. This may waste a few bytes, so? */
|
|
|
|
++r;
|
|
|
|
while (r<(*s-1)) if (*r=='\\') { *t++=*(r+1); r+=2; } else *t++=*r++;
|
|
|
|
*t='\0';
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else return (Token*)0;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
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 19:12:06 +00:00
|
|
|
|
2019-08-28 06:30:02 +00:00
|
|
|
/* scan_integer -- match an integer and return token */ /*{{{*/
|
|
|
|
Token *scan_integer(char **s)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-08-28 06:30:02 +00:00
|
|
|
char *r = *s;
|
2019-08-28 19:40:50 +00:00
|
|
|
bool ishex = (*s)[0] == '0' && (*s)[1] == 'x';
|
2019-08-28 06:30:02 +00:00
|
|
|
IntT i = STRTOINT(r, s, 0);
|
2019-08-28 19:40:50 +00:00
|
|
|
if (*s == r
|
|
|
|
|| **s == '.' || **s == 'e' || **s == 'E' || (ishex && **s == 'p'))
|
|
|
|
{ /* either doesn't look like a number, or looks like a float, not an int */
|
|
|
|
*s = r;
|
|
|
|
return NULLTOKEN;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-08-28 19:40:50 +00:00
|
|
|
/* looks like an int */
|
|
|
|
Token *n = malloc(sizeof(Token));
|
|
|
|
n->type = INT;
|
|
|
|
n->u.integer = i;
|
|
|
|
return n;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
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 19:12:06 +00:00
|
|
|
|
2019-08-28 06:30:02 +00:00
|
|
|
/* scan_flt -- match a floating point number */ /*{{{*/
|
|
|
|
Token *scan_flt(char **s)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-08-28 06:30:02 +00:00
|
|
|
char *t = *s;
|
2019-07-22 20:32:33 +00:00
|
|
|
char *end;
|
2019-08-28 06:30:02 +00:00
|
|
|
FltT x = STRTOFLT(t, &end);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
*s = end;
|
2019-08-28 06:30:02 +00:00
|
|
|
if (t !=* s && dblfinite(x) == NULL)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-08-28 06:30:02 +00:00
|
|
|
Token *n = malloc(sizeof(Token));
|
|
|
|
n->type = FLOAT;
|
|
|
|
n->u.flt = x;
|
2019-07-22 20:32:33 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-28 06:30:02 +00:00
|
|
|
*s = t;
|
|
|
|
return NULLTOKEN;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*}}}*/
|
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 19:12:06 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* op -- match an op and return token */ /*{{{*/
|
2019-08-28 06:30:02 +00:00
|
|
|
static Token *op(char **s)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
Token *n;
|
|
|
|
Operator op;
|
|
|
|
|
|
|
|
switch (**s)
|
|
|
|
{
|
|
|
|
case '+': op=PLUS; break;
|
|
|
|
case '-': op=MINUS; break;
|
|
|
|
case '*': op=MUL; break;
|
|
|
|
case '/': op=DIV; break;
|
|
|
|
case '%': op=MOD; break;
|
|
|
|
case '(': op=OP; break;
|
|
|
|
case ')': op=CP; break;
|
|
|
|
case ',': op=COMMA; break;
|
|
|
|
case '^': op=POW; break;
|
|
|
|
case '<': if (*(*s+1)=='=') { ++(*s); op=LE; } else op=LT; break;
|
|
|
|
case '>': if (*(*s+1)=='=') { ++(*s); op=GE; } else op=GT; break;
|
|
|
|
case '=': if (*(*s+1)=='=') { ++(*s); op=ISEQUAL; } else return (Token*)0; break;
|
|
|
|
case '~': if (*(*s+1)=='=') { ++(*s); op=ABOUTEQ; } else return (Token*)0; break;
|
|
|
|
case '!': if (*(*s+1)=='=') { ++(*s); op=NE; } else return (Token*)0; break;
|
|
|
|
default: return (Token*)0;
|
|
|
|
}
|
|
|
|
n=malloc(sizeof(Token));
|
|
|
|
n->type=OPERATOR;
|
|
|
|
n->u.op=op;
|
|
|
|
++(*s);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-09-03 08:41:37 +00:00
|
|
|
|
2019-08-28 06:30:02 +00:00
|
|
|
/* scan_ident -- match an identifier and return token */ /*{{{*/
|
|
|
|
Token *scan_ident(char **s)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
const char *begin;
|
|
|
|
Token *result;
|
|
|
|
|
|
|
|
if (isalpha((int)**s) || **s=='_' || **s=='@' || **s=='&' || **s=='.' || **s=='$')
|
|
|
|
{
|
|
|
|
int fident;
|
|
|
|
|
|
|
|
begin=*s; ++(*s);
|
|
|
|
while (isalpha((int)**s) || **s=='_' || **s=='@' || **s=='&' || **s=='.' || **s=='$' || isdigit((int)**s)) ++(*s);
|
2019-08-27 06:56:19 +00:00
|
|
|
result = malloc(sizeof(Token));
|
|
|
|
if (*s-begin == 3 && strncmp(begin, "and", 3) == 0)
|
|
|
|
{
|
|
|
|
result->type = OPERATOR;
|
|
|
|
result->u.op = LAND;
|
|
|
|
}
|
|
|
|
else if (*s-begin == 2 && strncmp(begin, "or", 2) == 0)
|
|
|
|
{
|
|
|
|
result->type = OPERATOR;
|
|
|
|
result->u.op = LOR;
|
|
|
|
}
|
|
|
|
else if ((fident = identcode(begin,(size_t)(*s-begin))) == NOT_A_FUNCTION)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-08-27 06:56:19 +00:00
|
|
|
result->type = LIDENT;
|
2019-07-22 20:32:33 +00:00
|
|
|
result->u.lident=malloc((size_t)(*s-begin+1));
|
|
|
|
(void)strncpy(result->u.lident,begin,(size_t)(*s-begin));
|
|
|
|
result->u.lident[*s-begin]='\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-27 06:56:19 +00:00
|
|
|
result->type = FIDENT;
|
|
|
|
result->u.fident = fident;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2019-08-27 06:56:19 +00:00
|
|
|
return NULLTOKEN;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
/* scan -- scan string into tokens */ /*{{{*/
|
2019-08-28 06:30:02 +00:00
|
|
|
Token **scan(char **s)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* variables */ /*{{{*/
|
|
|
|
Token **na,*n;
|
2019-08-28 06:30:02 +00:00
|
|
|
char *r;
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
/* compute number of tokens */ /*{{{*/
|
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 19:12:06 +00:00
|
|
|
r = *s;
|
|
|
|
while (*r == ' ') ++r;
|
2019-09-05 07:24:24 +00:00
|
|
|
size_t i = 0;
|
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 19:12:06 +00:00
|
|
|
for (; *r != '\0'; ++i)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
const char *or;
|
|
|
|
|
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 19:12:06 +00:00
|
|
|
or = r;
|
|
|
|
while (*r == ' ') ++r;
|
|
|
|
n = charstring(&r);
|
|
|
|
if (n == NULLTOKEN) n = op(&r);
|
2019-08-28 06:30:02 +00:00
|
|
|
if (n == NULLTOKEN) n = scan_integer(&r);
|
|
|
|
if (n == NULLTOKEN) n = scan_flt(&r);
|
|
|
|
if (n == NULLTOKEN) n = scan_ident(&r);
|
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 19:12:06 +00:00
|
|
|
if (or == r) { *s = r; return EMPTY_TVEC; }
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* allocate token space */ /*{{{*/
|
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 19:12:06 +00:00
|
|
|
na = malloc(sizeof(Token*)*(i+1));
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
|
|
|
/* store tokens */ /*{{{*/
|
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 19:12:06 +00:00
|
|
|
r = *s;
|
2019-07-22 20:32:33 +00:00
|
|
|
while (*r==' ') ++r;
|
2019-09-05 07:24:24 +00:00
|
|
|
for (size_t j = 0; j < i; ++j)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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 19:12:06 +00:00
|
|
|
while (*r == ' ') ++r;
|
|
|
|
n = charstring(&r);
|
|
|
|
if (n == NULLTOKEN) n = op(&r);
|
2019-08-28 06:30:02 +00:00
|
|
|
if (n == NULLTOKEN) n = scan_integer(&r);
|
|
|
|
if (n == NULLTOKEN) n = scan_flt(&r);
|
|
|
|
if (n == NULLTOKEN) n = scan_ident(&r);
|
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 19:12:06 +00:00
|
|
|
na[j] = n;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
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 19:12:06 +00:00
|
|
|
na[i] = NULLTOKEN;
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
|
|
|
return na;
|
|
|
|
}
|
|
|
|
/*}}}*/
|