-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
SyntaxError on use in expression of symbol with leading decimal digits #79
Comments
|
That's invalid input, and it did give a fairly good hint as to what's invalid about it. |
Oops, I was overzealous in reducing the reproducer to less-than minimal...
|
It appears that |
FYI, the error was hit using pcpp to do codegen with this preprocessing library (it works with gcc, clang, and the new conforming msvc preprocessor) |
Also FYI, I'm looking at using pcpp to create an amalgamated header I'm also evaluating if it can create nicer codegen than the native cpp's. |
the |
pcpp lacks a
when it should choose
In phase 3 input is decomposed into preprocessing tokens, Only in phase 7 are preprocessing tokens converted into tokens for translation. pcpp only has one set of |
Help! Can't work out how to hack it. Do the There's a comment on the
When set to zero and my edits are still ignored - |
Related issue #71, also notes the incorrect parse as glued |
This could be a straightforward fix (still can't work out how to test it). The current gcc lex.cc only processes This 2001 bugfix commit to the C preprocessor
shows Then, for The current evaluator should correctly interpret any In other words, Possible issues
|
You may find the ply parser docs at https://www.dabeaz.com/ply/ of use on how it works and generates the precalculated table files. |
Related issue in Boost.Wave 👋 BOOST_PP_CAT(1e, -1) pp-token bug fixed early 2006 |
A simple proof of concept change that fixes ned14#79. With it, pcpp can do codegen using the IREPEAT library. I believe it's conceptually correct, but my Python may not be; please test this against your suite and review the method (hack) carefully. There's not much code! Mostly deletions. The change removes CPP_INTEGER, effectively replacing it with PP_NUMBER, and entirely removes CPP_FLOAT as superfluous for preprocessing purposes. pp-number is sufficient for preprocessing to stage 4 The pp-number regex in the issue is incorrect, lifted from unpublished WG21 https://isocpp.org/files/papers/D2180R0.html "pp-number makes cpp dumber" (best proposal title ever). Instead, I crafted a regex based on the lastest C++ draft https://eel.is/c++draft/lex.ppnumber#ntref:pp-number which accepts character ' as digit separator: regex string r'\.?\d(\.|[\w_]|\'[\w_]|[eEpP][-+])*' (also admits binary literals, with digit separator, of course, so they can now be added to the Value parsing code) Only the conditional evaluator is required to interpret the numbers as integer constant expressions. This is achieved by hacky means: def p_expression_number(p): 'expression : PP_NUMBER' try: p[0] = Value(p[1]) except: p[0] = p[1] The idea is that if the parsed string p[1] can be interpreted as an integer constant-expression Value(p[1]) then do so, otherwise simply pass through the string for possible further pasting and processing. A robust method might check p[1] against the CPP_INTEGER regex (removed in this commit) for a full match, consuming all input. On the other hand, relying on Value to validate the input while parsing and to raise an exception on failure may be Pythonic. It seems that pp-number itself is a hack in the standard; I see no way to incorporate pp-number alongside INTEGER and FLOAT tokens meaningful in C; but then there's no need to. Happy Thanksgiving!
Here's a reduced reproducer:
then
pcpp test.h
givesIt looks like leading decimal digits are eagerly stripped when parsed for the expression.
The text was updated successfully, but these errors were encountered: