Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PP_NUMBER, remove CPP_INTEGER, CPP_FLOAT #80

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pcpp/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
willwray marked this conversation as resolved.
Show resolved Hide resolved
'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',
Expand Down Expand Up @@ -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'
Expand Down
13 changes: 5 additions & 8 deletions pcpp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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][-+])*'
willwray marked this conversation as resolved.
Show resolved Hide resolved
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):
Expand Down