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

[BUG REPORT]When printing with variables embedded in strings all occurrences of the variable in the string are converted into format specifier #149

Closed
adenashameem opened this issue Oct 2, 2020 · 12 comments
Assignees
Labels
bug Something isn't working KWoC'20 These issues are being listed as part of KWoC'20 moderate Moderate problem

Comments

@adenashameem
Copy link
Contributor

Describe the bug
When using the syntax provided for printing with variables embedded in strings, each and every occurrence of that variable even in the string part is converted into a format specifier, however only the occurrence of the variable after the '=' sign should be converted into a format specifier.

To Reproduce
Steps to reproduce the behavior:
simC code:
MAIN
var a_var = 42
print("The value of a_var = {a_var}")
END_MAIN

C code the above simC code generates right now:
#include <stdio.h>
int main() {
int a_var = 42;
printf("The value of %d = %d", a_var);

return 0;

}
This C code gives the output:
The value of 42 = 10109280

Expected behavior
Expected C code:
#include <stdio.h>
int main() {
int a_var = 42;
printf("The value of a_var = %d", a_var);

return 0;

}
Expected Output:
The value of a_var = 42

Desktop:

  • OS: [e.g. macOS]
@adenashameem adenashameem added the bug Something isn't working label Oct 2, 2020
@frankhart2018
Copy link
Member

Thanks @adenashameem for reporting the bug. Please also link this to #66 too. You can comment on that something like:-

Bug reported - When printing with variables embedded in strings all occurrences of the variable in the string are converted into format specifier #149.

@frankhart2018 frankhart2018 added the moderate Moderate problem label Nov 1, 2020
@cimplec cimplec deleted a comment from adenashameem Nov 1, 2020
@dhairyaj dhairyaj added the KWoC'20 These issues are being listed as part of KWoC'20 label Dec 4, 2020
@Saptashrungi
Copy link
Contributor

I would like to work on this issue, some minor changes will be required, I will suggest a solution for this tomorrow.

@frankhart2018
Copy link
Member

Sure assigning this to you @Saptashrungi.

@Saptashrungi
Copy link
Contributor

I went through the code base, where mapping is done for variables in expression after (, to avoid the bug above we need to add one more check if to ensure, the mapping and replacement from a_var to %d occurs only if it is between {}.

@frankhart2018
Copy link
Member

@Saptashrungi check_if is used to check if types are similar or not, the issue is in how the replacement is made, it is done using python's inbuilt replace function which replaces all occurrences of the substring in the string with the format specifier, using an index based approach to replace might be helpful here I believe.

@Saptashrungi
Copy link
Contributor

Yes I went through the expression function, where in a for loop we are replacing based on op_type I guess, so we are parsing through the string, we will replace only if curly braces are encountered, we can use index approach.

@frankhart2018
Copy link
Member

Yeah :)

@Saptashrungi
Copy link
Contributor

I am facing a problem in debugging, even after commenting out or change a significant part of code in simc_parser.py , I get same opcode.

@Saptashrungi
Copy link
Contributor

Yes

@Math-O5
Copy link
Collaborator

Math-O5 commented Dec 10, 2020

@frankhart2018 @Saptashrungi This issue should be closed?

@frankhart2018
Copy link
Member

Yeah this is merged.

@Math-O5 Math-O5 closed this as completed Dec 10, 2020
@Saptashrungi
Copy link
Contributor

@frankhart2018 @Saptashrungi This issue should be closed?

Yes it's fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working KWoC'20 These issues are being listed as part of KWoC'20 moderate Moderate problem
Projects
None yet
Development

No branches or pull requests

5 participants