kconfig: use specific tokens instead of T_ASSIGN for assignments
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Tue, 11 Dec 2018 11:01:01 +0000 (20:01 +0900)
committerChristian Lamparter <chunkeey@gmail.com>
Sun, 10 Feb 2019 21:32:13 +0000 (22:32 +0100)
Currently, the lexer returns T_ASSIGN for all of =, :=, and +=
associating yylval with the flavor.

I want to make the generated lexer as simple as possible. So, the
lexer should convert keywords to tokens without thinking about the
meaning.

   =  ->  T_EQUAL
  :=  ->  T_COLON_EQUAL
  +=  ->  T_PLUS_EQUAL

Unfortunately, Kconfig uses = instead of == for the equal operator.
So, the same token T_EQUAL is used for assignment and comparison.
The parser can still distinguish them from the context.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
config/zconf.l
config/zconf.y

index 81c1f40cdee6262a04e6f2e7bbd7301f23cede15..418ade946405a8dbf01b3c2154edbeeda9f360a7 100644 (file)
@@ -118,9 +118,9 @@ n   [A-Za-z0-9_-]
                        return T_VARIABLE;
                free(yylval.string);
        }
-       "="     { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; }
-       ":="    { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; }
-       "+="    { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_APPEND; return T_ASSIGN; }
+       "="     { BEGIN(ASSIGN_VAL); return T_EQUAL; }
+       ":="    { BEGIN(ASSIGN_VAL); return T_COLON_EQUAL; }
+       "+="    { BEGIN(ASSIGN_VAL); return T_PLUS_EQUAL; }
        [[:blank:]]+
        .       warn_ignored_character(*yytext);
        \n      {
index 7333e8e143631f7eb80880bf8ad6baf196346f51..653ef2c7c42e24e34e08829ab2e679f210c5db43 100644 (file)
@@ -70,6 +70,7 @@ static struct menu *current_menu, *current_entry;
 %token T_ALLNOCONFIG_Y
 %token T_BOOL
 %token T_CLOSE_PAREN
+%token T_COLON_EQUAL
 %token T_DEFAULT
 %token T_DEFCONFIG_LIST
 %token T_DEF_BOOL
@@ -79,11 +80,11 @@ static struct menu *current_menu, *current_entry;
 %token T_MODULES
 %token T_OPEN_PAREN
 %token T_OPTION
+%token T_PLUS_EQUAL
 %token T_STRING
 %token T_TRISTATE
 %token T_EOL
 %token <string> T_VARIABLE
-%token <flavor> T_ASSIGN
 %token <string> T_ASSIGN_VAL
 
 %left T_OR
@@ -101,6 +102,7 @@ static struct menu *current_menu, *current_entry;
 %type <id> end
 %type <menu> if_entry menu_entry choice_entry
 %type <string> word_opt assign_val
+%type <flavor> assign_op
 
 %destructor {
        fprintf(stderr, "%s:%d: missing end statement for this entry\n",
@@ -478,7 +480,13 @@ word_opt: /* empty */                      { $$ = NULL; }
 
 /* assignment statement */
 
-assignment_stmt:  T_VARIABLE T_ASSIGN assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
+assignment_stmt:  T_VARIABLE assign_op assign_val T_EOL        { variable_add($1, $3, $2); free($1); free($3); }
+
+assign_op:
+         T_EQUAL       { $$ = VAR_RECURSIVE; }
+       | T_COLON_EQUAL { $$ = VAR_SIMPLE; }
+       | T_PLUS_EQUAL  { $$ = VAR_APPEND; }
+;
 
 assign_val:
        /* empty */             { $$ = xstrdup(""); };