From 681fb9aa0fd7134daffd7494fa320ea3a7ef67c7 Mon Sep 17 00:00:00 2001 From: Lewis Van Winkle Date: Tue, 23 Feb 2016 17:29:03 -0600 Subject: [PATCH] Allow empty parens for function0. --- README.md | 2 +- tinyexpr.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e1361e..2fd59db 100644 --- a/README.md +++ b/README.md @@ -219,7 +219,7 @@ TinyExpr parses the following grammar: = {("*" | "/" | "%") } = {"^" } = {("-" | "+")} - = | | | "(" "," ")" | "(" ")" + = | | {"(" ")"} | | "(" "," ")" | "(" ")" In addition, whitespace between tokens is ignored. diff --git a/tinyexpr.c b/tinyexpr.c index 12c8b3a..4f3bee2 100644 --- a/tinyexpr.c +++ b/tinyexpr.c @@ -205,7 +205,7 @@ static te_expr *expr(state *s); static te_expr *power(state *s); static te_expr *base(state *s) { - /* = | | | "(" "," ")" | "(" ")" */ + /* = | | {"(" ")"} | | "(" "," ")" | "(" ")" */ te_expr *ret; switch (s->type) { @@ -225,6 +225,14 @@ static te_expr *base(state *s) { ret = new_expr(TE_FUNCTION0, 0, 0); ret->f0 = s->f0; next_token(s); + if (s->type == TOK_OPEN) { + next_token(s); + if (s->type != TOK_CLOSE) { + s->type = TOK_ERROR; + } else { + next_token(s); + } + } break; case TOK_FUNCTION1: