Re: [PATCH 04/17] genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts

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

 



On Tue, Jan 14, 2025 at 12:03 AM Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
>
> The genksyms parser has ambiguities in its grammar, which are currently
> suppressed by a workaround in scripts/genksyms/Makefile.
>
> Building genksyms with W=1 generates the following warnings:
>
>     YACC    scripts/genksyms/parse.tab.[ch]
>   scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
>   scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
>   scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
>
> The comment in the parser describes the current problem:
>
>     /* This wasn't really a typedef name but an identifier that
>        shadows one.  */
>
> Consider the following simple C code:
>
>     typedef int foo;
>     void my_func(foo foo) {}
>
> In the function parameter list (foo foo), the first 'foo' is a type
> specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
>
> However, the lexer cannot distinguish between the two. Since 'foo' is
> already typedef'ed, the lexer returns TYPE for both instances, instead
> of returning IDENT for the second one.
>
> To support shadowed identifiers, IDENT can be reduced to either a

   IDENT -> TYPE


> simple_type_specifier or a direct_abstract_declarator, which creates
> a grammatical ambiguity.
>
> Without analyzing the grammar context, it is very difficult to resolve
> this correctly.
>
> This commit introduces a flag, dont_want_type_specifier, which allows
> the parser to inform the lexer whether an identifier is expected. When
> dont_want_type_specifier is true, the type lookup is suppressed, and
> the lexer returns IDENT regardless of any preceding typedef.
>
> After this commit, only 3 shift/reduce conflicts will remain.
>
> Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx>


-- 
Best Regards
Masahiro Yamada





[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux