ProSurfer73 / Macro-Parser

A C/C++ macro calculator
BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

Work with all macro arguments #44

Closed ProSurfer73 closed 1 year ago

ProSurfer73 commented 2 years ago

For now, MacroParser only works with string ending with '(x)'. The goal would be to make it work with any number of arguments (x, y) , and all possible names for this argument ( a , b , x , X , Y , y , ...). But it is really going to be used often enough ?

ProSurfer73 commented 1 year ago

https://github.com/ProSurfer73/Macro-Parser/commit/1caf6da2d9d70ae937b19284693c1c477dcdb7a7

ProSurfer73 commented 1 year ago

Thanks to this commit https://github.com/ProSurfer73/Macro-Parser/commit/c58d01520d02d48ced38277a9af7d6f1449332c1 the calculate command is partially implemented (part circled in green). image But there are still some issues, as you can see by the picture above (part circled in red).

ProSurfer73 commented 1 year ago

image The case in which a macro with parameters is inside another macro with parameters is yet not treated.

ProSurfer73 commented 1 year ago

The program currently crashes when this last command is run.

The debugger in Code::Blocks was not able to tell me the line at which the program had crashed.

Thanks to Visual Studio, I was able to debug the program and here is the line at which it crashes (in stringeval.cpp file) : image

ProSurfer73 commented 1 year ago

I replaced the line mentioned by : if(!p.first.empty() && p.first.back() != ')') And the execution seems to be running smoothly with Visual Studio IDE. But it keeps on crashing using gcc compiler and Code::Blocks. Lets investigate why.

ProSurfer73 commented 1 year ago

Lets try to use the GDB commandline to debug our program. I looked for oneline videos on how to debug our program with GDB. Lets first try to locate the symbol files. image

ProSurfer73 commented 1 year ago

image From what I was able to debug, the crash occurred in one the function from the c++ standard library (but unlocated.

ProSurfer73 commented 1 year ago

I used gdb and made the program run line by line. This way, I was able to find the line that was causing the crash to the program (please see the picture below). image

ProSurfer73 commented 1 year ago

crash fixed thanks to this commit: https://github.com/ProSurfer73/Macro-Parser/commit/42e2f1ad735eebb7992503b3a4ce3b0a4cd78d24.

ProSurfer73 commented 1 year ago

Unfortunately, the expression still cannot be calculated: image Lets debug and fix that !

ProSurfer73 commented 1 year ago

I decided to type and evaluate this expression. image Lets debug and fix the situation !

ProSurfer73 commented 1 year ago

Again, by using GDB debugger and by running the program line by line, I was able to locate the source of the error : image Lets now patch this unwanted exception thrown.

ProSurfer73 commented 1 year ago

The previous commit fixes the evaluation of this expression: image

ProSurfer73 commented 1 year ago

The problematic expression is now correctly evaluated (as you can see by the picture below) 👍 image

ProSurfer73 commented 1 year ago

But now we have this expression that cant be evaluated : image

ProSurfer73 commented 1 year ago

Previous commit fixed the issue. image

ProSurfer73 commented 1 year ago

image We now face this expression still incorrectly evaluated. ( the result should be 55 instead of 33 )

ProSurfer73 commented 1 year ago

image Previous commit fixed the issue.

ProSurfer73 commented 1 year ago

This type of macro now seem to be supported. Lets mark this issue as closed !