fully allow upper-case letters in variable names

This commit is contained in:
Lewis Van Winkle
2021-03-03 16:20:38 -06:00
parent 8d7ebbba53
commit 61af1dd24c
3 changed files with 8 additions and 8 deletions

View File

@@ -255,11 +255,10 @@ TinyExpr parses the following grammar:
In addition, whitespace between tokens is ignored.
Valid variable names consist of a lower case letter followed by any combination
of: lower case letters *a* through *z*, the digits *0* through *9*, and
underscore. Constants can be integers, decimal numbers, or in scientific
notation (e.g. *1e3* for *1000*). A leading zero is not required (e.g. *.5*
for *0.5*)
Valid variable names consist of a letter followed by any combination of:
letters, the digits *0* through *9*, and underscore. Constants can be integers,
decimal numbers, or in scientific notation (e.g. *1e3* for *1000*). A leading
zero is not required (e.g. *.5* for *0.5*)
## Functions supported

View File

@@ -174,8 +174,9 @@ void test_syntax() {
{"1*2(+4", 4},
{"1*2(1+4", 4},
{"a+5", 1},
{"A+5", 1},
{"Aa+5", 1},
{"!+5", 1},
{"_a+5", 1},
{"#a+5", 1},
{"1^^5", 3},
{"1**5", 3},
{"sin(cos5", 8},

View File

@@ -243,7 +243,7 @@ void next_token(state *s) {
s->type = TOK_NUMBER;
} else {
/* Look for a variable or builtin function call. */
if (s->next[0] >= 'a' && s->next[0] <= 'z') {
if (isalpha(s->next[0])) {
const char *start;
start = s->next;
while (isalpha(s->next[0]) || isdigit(s->next[0]) || (s->next[0] == '_')) s->next++;