]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
moving keywords into an array
authorWolfgang (Blub) Bumiller <blub@speed.at>
Mon, 19 Nov 2012 17:57:37 +0000 (18:57 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Mon, 19 Nov 2012 18:20:26 +0000 (19:20 +0100)
lexer.c

diff --git a/lexer.c b/lexer.c
index a71e50f6cfa9fcbdd19224f17c48a706ce06f6be..e4328bec26f37b6b391019cfc99aebdf282fcf1b 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -6,6 +6,33 @@
 #include "gmqcc.h"
 #include "lexer.h"
 
+/*
+ * List of Keywords
+ */
+
+/* original */
+static const char *keywords_qc[] = {
+    "for", "do", "while",
+    "if", "else",
+    "local",
+    "return",
+    "const"
+};
+static size_t num_keywords_qc = sizeof(keywords_qc) / sizeof(keywords_qc[0]);
+
+/* For fte/gmgqcc */
+static const char *keywords_fg[] = {
+    "var",
+    "switch",
+    "struct", "union",
+    "break", "continue"
+};
+static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]);
+
+/*
+ * Lexer code
+ */
+
 char* *lex_filenames;
 
 void lexerror(lex_file *lex, const char *fmt, ...)
@@ -1147,29 +1174,17 @@ int lex_do(lex_file *lex)
         } else if (!strcmp(v, "vector")) {
             lex->tok.ttype = TOKEN_TYPENAME;
             lex->tok.constval.t = TYPE_VECTOR;
-        } else if (!strcmp(v, "for")  ||
-                 !strcmp(v, "while")  ||
-                 !strcmp(v, "do")     ||
-                 !strcmp(v, "if")     ||
-                 !strcmp(v, "else")   ||
-                 !strcmp(v, "local")  ||
-                 !strcmp(v, "return") ||
-                 !strcmp(v, "not")    ||
-                 !strcmp(v, "const"))
-        {
-            lex->tok.ttype = TOKEN_KEYWORD;
-        }
-        else if (opts_standard != COMPILER_QCC)
-        {
-            /* other standards reserve these keywords */
-            if (!strcmp(v, "switch") ||
-                !strcmp(v, "struct") ||
-                !strcmp(v, "union")  ||
-                !strcmp(v, "break")  ||
-                !strcmp(v, "continue") ||
-                !strcmp(v, "var"))
-            {
-                lex->tok.ttype = TOKEN_KEYWORD;
+        } else {
+            size_t kw;
+            for (kw = 0; kw < num_keywords_qc; ++kw) {
+                if (!strcmp(v, keywords_qc[kw]))
+                    return (lex->tok.ttype = TOKEN_KEYWORD);
+            }
+            if (opts_standard != COMPILER_QCC) {
+                for (kw = 0; kw < num_keywords_fg; ++kw) {
+                    if (!strcmp(v, keywords_fg[kw]))
+                        return (lex->tok.ttype = TOKEN_KEYWORD);
+                }
             }
         }