diff --git a/pcpp/evaluator.py b/pcpp/evaluator.py index 38abe20..498ec1f 100644 --- a/pcpp/evaluator.py +++ b/pcpp/evaluator.py @@ -357,7 +357,7 @@ def __gt__(self, other): # The subset of tokens from Preprocessor used in preprocessor expressions tokens = ( - 'CPP_ID', 'CPP_INTEGER', 'CPP_CHAR', 'CPP_STRING', + 'CPP_ID', 'PP_NUMBER', 'CPP_CHAR', 'CPP_STRING', 'CPP_PLUS', 'CPP_MINUS', 'CPP_STAR', 'CPP_FSLASH', 'CPP_PERCENT', 'CPP_BAR', 'CPP_AMPERSAND', 'CPP_TILDE', 'CPP_HAT', 'CPP_LESS', 'CPP_GREATER', 'CPP_EXCLAMATION', 'CPP_QUESTION', 'CPP_LPAREN', 'CPP_RPAREN', @@ -394,8 +394,12 @@ def p_error(p): raise SyntaxError("at EOF") def p_expression_number(p): - 'expression : CPP_INTEGER' - p[0] = Value(p[1]) + 'expression : PP_NUMBER' + try: + p[0] = Value(p[1]) + except: + p[0] = p[1] + def p_expression_character(p): 'expression : CPP_CHAR' diff --git a/pcpp/parser.py b/pcpp/parser.py index 8e6a10a..6e55987 100644 --- a/pcpp/parser.py +++ b/pcpp/parser.py @@ -27,7 +27,7 @@ # ----------------------------------------------------------------------------- tokens = ( - 'CPP_ID','CPP_INTEGER', 'CPP_FLOAT', 'CPP_STRING', 'CPP_CHAR', 'CPP_WS', 'CPP_LINECONT', 'CPP_COMMENT1', 'CPP_COMMENT2', + 'CPP_ID', 'PP_NUMBER', 'CPP_STRING', 'CPP_CHAR', 'CPP_WS', 'CPP_LINECONT', 'CPP_COMMENT1', 'CPP_COMMENT2', 'CPP_POUND','CPP_DPOUND', 'CPP_PLUS', 'CPP_MINUS', 'CPP_STAR', 'CPP_FSLASH', 'CPP_PERCENT', 'CPP_BAR', 'CPP_AMPERSAND', 'CPP_TILDE', 'CPP_HAT', 'CPP_LESS', 'CPP_GREATER', 'CPP_EQUAL', 'CPP_EXCLAMATION', 'CPP_QUESTION', 'CPP_LPAREN', 'CPP_RPAREN', 'CPP_LBRACKET', 'CPP_RBRACKET', 'CPP_LCURLY', 'CPP_RCURLY', @@ -111,15 +111,12 @@ def t_CPP_LINECONT(t): # Identifier t_CPP_ID = r'[A-Za-z_][\w_]*' -# Integer literal -def CPP_INTEGER(t): - r'(((((0x)|(0X))[0-9a-fA-F]+)|(\d+))([uU][lL]|[lL][uU]|[uU]|[lL])?)' +# Preprocessor number +def PP_NUMBER(t): + r'\.?\d(\.|[\w_]|\'[\w_]|[eEpP][-+])*' return t -t_CPP_INTEGER = CPP_INTEGER - -# Floating literal -t_CPP_FLOAT = r'((\d+)(\.\d+)(e(\+|-)?(\d+))?|(\d+)e(\+|-)?(\d+))([lL]|[fF])?' +t_PP_NUMBER = PP_NUMBER # String literal def t_CPP_STRING(t):