Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Handling leading zeros in integer literals #2568

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

Merged
merged 3 commits into from
Mar 8, 2024

Conversation

hankluo6
Copy link
Contributor

@hankluo6 hankluo6 commented Mar 3, 2024

Fixed #2002

I catch this error in the tokenizer because it removes trailing zeros in lex_int. Also, to handle the case of all zeros, we must allow the tokenizer to process the number first.

// Oct
s = s + 2;
uint64_t n = get_value((char*)s, 8, loc);
u.from_smallint(n);
} else {
lex_dec_int_large(al, s, e, u);
if (s[0] == '0' && u.n != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @hankluo6 ! Thanks for this!

I think this is not the right file to make the changes. Your idea is correct. Please make the same changes in tokenizer.cpp. 👍

Welcome to LPython!

Copy link
Contributor Author

@hankluo6 hankluo6 Mar 3, 2024

Choose a reason for hiding this comment

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

Hi @kmr-srbh

Thanks for your feedback! I'm excited to be part of LPython! I think tokenizer.cpp is generated from tokenizer.re using re2c so I made change on this file. Please let me know if I'm mistaken.

@mrdaybird
Copy link
Contributor

tokenizer.cpp file is an auto-generated file, created by re2c when you run the build0.sh script using the tokenizer.re file. Any changes needed, will have to be made to the tokenizer.re file.

@kmr-srbh
Copy link
Contributor

kmr-srbh commented Mar 3, 2024

Oh! I am sorry. @mrdaybird is right. I had tested your changes through the tokenizer.cpp file and built using build1.sh. I had completely missed the comment on top of the file. I am sorry for the mistake.

Thanks for the correction @mrdaybird !

Copy link
Collaborator

@ubaidsk ubaidsk left a comment

Choose a reason for hiding this comment

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

@hankluo6 This looks good to me! Thanks for this! Please add an error reference test (for example as in cbb79b6) and we can merge this.

After adding a test, you need to update the reference tests using ./run_tests.py -u and commit the changes/updations.

@Thirumalai-Shaktivel
Copy link
Collaborator

Please mark this PR ready for review once it is ready.

@Thirumalai-Shaktivel Thirumalai-Shaktivel marked this pull request as draft March 7, 2024 06:45
@hankluo6 hankluo6 marked this pull request as ready for review March 8, 2024 00:24
@hankluo6
Copy link
Contributor Author

hankluo6 commented Mar 8, 2024

@hankluo6 This looks good to me! Thanks for this! Please add an error reference test (for example as in cbb79b6) and we can merge this.

After adding a test, you need to update the reference tests using ./run_tests.py -u and commit the changes/updations.

@Shaikh-Ubaid @Thirumalai-Shaktivel I added a new test, could you review it? Thanks!

Copy link
Collaborator

@ubaidsk ubaidsk left a comment

Choose a reason for hiding this comment

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

Perfect! Thanks! Great work @hankluo6!

@ubaidsk ubaidsk merged commit 8ad6975 into lcompilers:main Mar 8, 2024
@hankluo6 hankluo6 deleted the leading_zero branch May 10, 2024 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CPython does not admit leading 0 in ints without an o or [xX]
5 participants