bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 9/9] bistromathic: use symbol numbers instead of YYTRANSLATE


From: Akim Demaille
Subject: [PATCH 9/9] bistromathic: use symbol numbers instead of YYTRANSLATE
Date: Sat, 28 Mar 2020 18:40:06 +0100

* 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 819313c9..3659b30f 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 (token, text, strlen (text)) == 0)
+            matches[match++] = strdup (token);
+          break;
+        }
       }
 
   // Find the longest common prefix, and install it in matches[0], as
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]