Skip to content

Add support for C11 _Generic selection (#559)#591

Open
mariam851 wants to merge 1 commit intoeliben:mainfrom
mariam851:support-generic-selection-559
Open

Add support for C11 _Generic selection (#559)#591
mariam851 wants to merge 1 commit intoeliben:mainfrom
mariam851:support-generic-selection-559

Conversation

@mariam851
Copy link

@mariam851 mariam851 commented Jan 16, 2026

Hi @eliben,

This PR implements support for the C11 _Generic keyword, addressing issue #559.

The implementation follows the C11 standard by adding _Generic as a primary expression.

Changes:
Lexer: Added _GENERIC to the keywords list in c_lexer.py.

AST:

Updated _c_ast.cfg with GenericSelection and GenericAssociation nodes.

Regenerated c_ast.py to include the new node classes.

Parser:

Added p_primary_expression_6 to support generic_selection.

Added rules for generic_selection, generic_assoc_list, and generic_association.

Updated p_primary_expression to include the new rule.

Screenshot (46)

Validation:
Conflicts: After adding the rules, the parser now reports 173 shift/reduce and 180 reduce/reduce conflicts (a minimal increase of 3/3, which is expected for this feature).

Manual Testing: Verified with a test script parsing complex _Generic expressions.

update: I've run the tests locally using python -m unittest discover tests and everything passed (133 tests). Ready for your review whenever the workflows are approved.

@eliben
Copy link
Owner

eliben commented Jan 22, 2026

The code of pycparser has been significantly refactored for the latest release.

If you're interested, please adjust the PR to the new parser structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants