Skip to content

Add lexer support for complex literals.#594

Open
manueljacob wants to merge 1 commit intoeliben:mainfrom
manueljacob:complex_literals
Open

Add lexer support for complex literals.#594
manueljacob wants to merge 1 commit intoeliben:mainfrom
manueljacob:complex_literals

Conversation

@manueljacob
Copy link
Copy Markdown
Contributor

They are part of the current C2y ISO draft (included by N3298 [1]).

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3298.htm

They are part of the current C2y ISO draft (included by N3298 [1]).

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3298.htm
Comment thread pycparser/c_lexer.py
_bad_string_literal = '"' + _string_char + "*" + _bad_escape + _string_char + '*"'

# floating constants (K&R2: A.2.5.3)
_floating_suffix_opt = r"([FfLl][iIjJ]?|[iIjJ][FfLl]?)?"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're following the standards now (rather than K&R2), could you ask you to follow the clauses listed in the linked doc?

I.e. break it to floating-suffix, real-floating-suffix, complex-suffix, etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this apply to whole floating-literal, or just floating-suffix?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the suffix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m unsure whether and how to change the comment “# floating constants (K&R2: A.2.5.3)” in this case.

Another issue: The aforementioned standard also contains decimal literals (suffixes df, dd, dl, DF, DD, DL; orthogonal to complex suffixes). They were added to C23, i.e. before complex literals.

If following standards, it would be consistent to support them in the lexer as well. This could be introduced in the same or a separate commit. Alternatively, I can use the names of the clauses from the standards but omit the decimal suffixes for now.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m unsure whether and how to change the comment “# floating constants (K&R2: A.2.5.3)” in this case.

Feel free to omit it or point to the new draft PDF. Unfortunately the link to open-std.org almost always fails to open in my browser; are you aware of an alternative place where we can point?

Another issue: The aforementioned standard also contains decimal literals (suffixes df, dd, dl, DF, DD, DL; orthogonal to complex suffixes). They were added to C23, i.e. before complex literals.

This can be done in either the same PR or a separate PR, whatever you feel is right. My only request is that each PR on its own is self-contained.

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