[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/21] bistromathic: use symbol numbers instead of YYTRANSLATE
From: |
Akim Demaille |
Subject: |
[PATCH 09/21] bistromathic: use symbol numbers instead of YYTRANSLATE |
Date: |
Wed, 1 Apr 2020 08:37:35 +0200 |
* examples/c/bistromathic/parse.y: here.
---
examples/c/bistromathic/parse.y | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index 3ada1ff3..a5d15694 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -386,23 +386,25 @@ completion (const char *text, int start, int end)
char **matches = calloc (ntokens + symbol_count () + 2, sizeof *matches);
int match = 1;
for (int i = 0; i < ntokens; ++i)
- if (tokens[i] == YYTRANSLATE (TOK_VAR))
+ switch (tokens[i])
{
+ case YYSYMBOL_FUN:
for (symrec *s = sym_table; s; s = s->next)
- if (s->type == TOK_VAR && strncmp (text, s->name, len) == 0)
+ if (s->type == TOK_FUN && strncmp (text, s->name, len) == 0)
matches[match++] = strdup (s->name);
- }
- else if (tokens[i] == YYTRANSLATE (TOK_FUN))
- {
+ break;
+ case YYSYMBOL_VAR:
for (symrec *s = sym_table; s; s = s->next)
- if (s->type == TOK_FUN && strncmp (text, s->name, len) == 0)
+ if (s->type == TOK_VAR && strncmp (text, s->name, len) == 0)
matches[match++] = strdup (s->name);
- }
- else
- {
- const char* token = yysymbol_name (tokens[i]);
- if (strncmp (token, text, strlen (text)) == 0)
- matches[match++] = strdup (token);
+ break;
+ default:
+ {
+ const char* token = yysymbol_name (tokens[i]);
+ if (strncmp (text, token, len) == 0)
+ matches[match++] = strdup (token);
+ break;
+ }
}
// Find the longest common prefix, and install it in matches[0], as
--
2.26.0
- [PATCH 00/21] Use, Akim Demaille, 2020/04/01
- [PATCH 01/21] style: comment changes about token numbers, Akim Demaille, 2020/04/01
- [PATCH 02/21] yacc.c: introduce an enum that defines the symbol's number, Akim Demaille, 2020/04/01
- [PATCH 04/21] yacc.c: use yysymbol_type_t instead of int for yytoken, Akim Demaille, 2020/04/01
- [PATCH 03/21] regen, Akim Demaille, 2020/04/01
- [PATCH 06/21] regen, Akim Demaille, 2020/04/01
- [PATCH 05/21] yacc.c: also define a symbol number for the empty token, Akim Demaille, 2020/04/01
- [PATCH 08/21] regen, Akim Demaille, 2020/04/01
- [PATCH 07/21] yacc.c: prefer YYSYMBOL_YYERROR to YYSYMBOL_error, Akim Demaille, 2020/04/01
- [PATCH 09/21] bistromathic: use symbol numbers instead of YYTRANSLATE,
Akim Demaille <=
- [PATCH 11/21] regen, Akim Demaille, 2020/04/01
- [PATCH 10/21] yysymbol_type_t: always assign an enumerator, Akim Demaille, 2020/04/01
- [PATCH 12/21] yacc.c: revert to not using yysymbol_type_t in the yytranslate table, Akim Demaille, 2020/04/01
- [PATCH 13/21] regen, Akim Demaille, 2020/04/01
- [PATCH 14/21] yacc.c: fix more errors from make maintainer-check-g++, Akim Demaille, 2020/04/01
- [PATCH 15/21] regen, Akim Demaille, 2020/04/01
- [PATCH 16/21] glr.c: use yysymbol_type_t, YYSYMBOL_YYEOF etc., Akim Demaille, 2020/04/01
- [PATCH 18/21] regen, Akim Demaille, 2020/04/01
- [PATCH 17/21] glr.c, yacc.c: propagate yysymbol_type_t, Akim Demaille, 2020/04/01
- [PATCH 19/21] glr.c: remove the yySymbol alias, Akim Demaille, 2020/04/01