From a4a7127dadf79ebf0deacf49f70ed9e588c40596 Mon Sep 17 00:00:00 2001 From: yaroslav-o <29219583+yaroslav-o@users.noreply.github.com> Date: Wed, 25 Sep 2019 05:44:54 -0700 Subject: Recognize integer multicharacter constants like 'ABCD' (#350) Recognize integer multicharacter constants like 'ABCD' The feature I am adding is defined here - 5th case. https://en.cppreference.com/w/c/language/character_constant Also here: 6.4.4.4.10 of C99. Put simply, pycparser thought a statement like this is an error: int a = 'ABCD'; However it is not. It is likely possible to just modify char_const regular expression in c_lexer.py:240 to allow longer characters, but the way it is done in this PR - multicharacter constants are clearly separated. I am also limiting the length of multicharacter const integers to 4 characters - this matches VS compiler behavior (gcc allows any length with a warning) and lets pycparser NOT consider lengthy single-quoted strings as integers - these would be nonsensical anyway. --- pycparser/c_parser.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pycparser/c_parser.py') diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py index 87d6c5e..4cf96fa 100644 --- a/pycparser/c_parser.py +++ b/pycparser/c_parser.py @@ -1766,6 +1766,7 @@ class CParser(PLYParser): | INT_CONST_OCT | INT_CONST_HEX | INT_CONST_BIN + | INT_CONST_CHAR """ uCount = 0 lCount = 0 -- cgit v1.2.1