[SOLVED] PNF: Help with a Loop to Identify extrai values
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
unsigned long ifcounter = 0, ifcounter2 = 0, sifcounter = 0;
for (unsigned long i = 0, j = reg.ecount; i != reg.ecount; i += 3, j -= 3)
{
if (mem.get(i + 1) == TSTRING)
{
unsigned long is = 0;
for (is = i + 2; mem.get(is) != 0; ++is)
;
++is;
j = i;
i = is;
i -= 3;
continue;
}
if (mem.get(i) == IIF || mem.get(j) == IENDIF || mem.get(i) == IIFELSE || mem.get(j) == IEIF)
{
if (mem.get(i) == IIF)
{
++ifcounter;
reg.inif.insert();
reg.ifflag.insert();
}
if (mem.get(j) == IEIF)
{
++ifcounter2;
ifcounter = ifcounter2;
}
reg.extrai.put(i, ifcounter);
}
}
It's supposed to load the extrai values, but it doesn't work.
Here's a brief explanation of what's supposed to be going on.
This is running a program. A program has a variable number of memory slots. It has the same amount of extrai values. extrai is a register. extrai is computed at run time, during the load. The rest of the information comes from a file.
A file has a signature: !@.PNF
A file has a series of numbers.
Generally the first number is the instruction, the second, the type, and the third, the operand.
For ifs, extrai is supposed to count the ifnumber. That's where this goes wrong. This is a loop that is computed at load time.
It's supposed to count the ifs, and then load extrai with the ifnumber. Ifs look like this:
Where anything inbetween {} or [] is optional. It's got the same if belonging rules as C++, where the last else will belong to the last if basically. My loops supposed to reflect that, but it fails. Please help. Thanks!
Last edited by des_a; 03-18-2019 at 11:03 AM.
Reason: Formatting error.
If variable i is equal to reg.ecount, then the loop will never execute.
What have you done to debug this? You gave code, but not all references contained within the code.
Run GDB on this and single step through it using some watchpoints on the relevant variables. There are some links in my signature giving instruction about how to accomplish this.
You've got this class reg containing methods and variables which are not defined, nor described here. Same thing for the mem class. One can only infer what things mean if they come close in descriptive names, however that's not the way it should be because mistakes can be made by way of incorrect assumptions.
Further, there are tons of if-test result conditions where you are using definitions, macros, or type defines; once again, none of these are referenced or defined.
At this point I don't understand what, if any, question remains. You've posted so much additional code of similar lack of background explanation.
des_a, I know that you have been pointed here previously, but I ask you again to please review the Site FAQ for guidance in asking well formed questions.
The file signature, more blocks of code and your PNF language syntax are not relevant nor helpful to others taking their time to try to understand and answer your question.
If you are troubleshooting a loop problem, then begin by defining a simplest case which will reproduce the problem, with well defined loop parameters and entry and exit conditions. Then try to troubleshoot it using printf statements to show the state of those parameters on each pass and use gdb to help figure it out. If you cannot figure it out, then you will have at least collected the necessary information to post here when asking for help.
Please refrain from posting blocks of code and asking others to first try to understand how it should all work, then why it may not be working. That is not a proper use of this forum and is not respectful of the time others contribute to help with your problem.
Help others help you by presenting a minimal test case with well defined parameters relevant to a clearly stated question.
Last edited by astrogeek; 03-19-2019 at 11:58 PM.
Reason: tpoy
It looks like I didn't define the question well enough. The problem I'm facing may not be the loop at all anymore. The problem may be somewhere else in the code, probably in my PNF::execute() function.
If this is still not clear, I will just close this thread. I have one other possible source I can think of to find more information on what's going on, besides "luck". If I need to, I will do that, and then see what that produces, and then if needed still, THEN come back here, with hopefully a better question. If you need to tell me whether I should do that or not. Thanks!
If this is still not clear, I will just close this thread. I have one other possible source I can think of to find more information on what's going on, besides "luck". If I need to, I will do that, and then see what that produces, and then if needed still, THEN come back here, with hopefully a better question. If you need to tell me whether I should do that or not. Thanks!
I rather feel you could mark this as solved. This effectively closes the discussion
Quote:
Originally Posted by des_a
Documentation on the language so far.
Well aware of your history here and I'm not interested in investing my time and energy with helping you to create a language where you seem to be the sole proponent of it, and I do not agree with the premise for this language.
Meanwhile, your first post here used code in the C language, which is what I was addressing.
Your proposed language is mostly C, or very similar.
Quick review of that syntax tells me that there's nothing I can't do in the C language and that you've just written a wrapper for the C language.
To me this is a supporting architecture which I'd use for an R&D project. That's how things are done, you create customized macros, enumerations, type definitions, and functions to help the form of your architecture be what you intend it to be.
As Astrogeek says, you should review the forum guidelines about how to ask an effective question.
If you are going to persist with discussions about your invented language, then literally every thread you start should have a couple of things (a) a clear statement at the top of the first post which states this is what it is about, not "I have this loop" followed by a bunch of code and then continued discussion on your part with little direct questions, and (b) reference links for those interested in reviewing the language in general, such as your grammar document, and other information about this language.
Otherwise you will be wasting your time and the time of others
To me this is a supporting architecture which I'd use for an R&D project. That's how things are done, you create customized macros, enumerations, type definitions, and functions to help the form of your architecture be what you intend it to be.
I agree. It's not what I intend it to be yet. But every working piece gets closer to what I intend it to be.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.