Topic: debug help with iFs and DOs

computer MacMini M4, OS 15.5, SimplyFortran 3.40 build 4427

I'm spending too much time trying to scan through the code, looking for a mismatched parentheses, or a Do without an EndDo.

I'd think it would be easy - count all the do's and count all the EndDo's. But I'm thinking a mismatched parentheses in an IF/Then construction is messing up the Do/Enddo pairing.

Is there a tool in SimplyFortran that points more directly to the error. I can imagine it is difficult because the code doesn't know my intent. I'm trying to use indents to group sections into matching units.

Just wondering if there's another way?

Re: debug help with iFs and DOs

I'll try the "binary search" approach: comment the whole program, then uncomment to make "breaks" at appropriate places—like the first half of the program vs. the last half. That will narrow down the area where the problem occurs.

Though the error says, "Missing EndDo," I'm guessing that's a secondary effect of mismatched parentheses.

I wonder if a "scratch pad" area for syntax debugging would be handy. Like I could copy/paste a section of code in the SyntaxChecker window, and it would ferret out any problems. Just a thought.

Re: debug help with iFs and DOs

Trying to sort out missing END statements can be particularly frustrating, and our compiler can produce frustrating messages that don't point to the originating DO or equivalent statement. 

A "syntax checker" window is interesting but complicated.  How would it handle variables?  Would you need to include entire subroutines or functions?  Just an arbitrary block of code would almost certainly produce errors from undeclared variables or miss errors by assuming implicit declarations.  There'd have to be a good amount of thought put into such a tool, which, admittedly, would be quite helpful.

Jeff Armstrong
Approximatrix, LLC

Re: debug help with iFs and DOs

Yes - having an algorithm determine what I intended with my indents and parentheses would be challenging. As I suspected, the problem was not with a missing EndDo - the compiler error message - it was caused by a missing endif.

One solution is for me to become more familiar with using the Modules, so I can move units of working code out of the "production" path.

I recall one compiler package that used different colored vertical trace lines for the If/endif, or do/enddo (and other pairs). SimplyFortran has vertical tab lines but not trace lines - like the vertical tab lines, but tied to any if/endif pair.

If those lines were there, I could easily trace any IF to its EndIF mate. If there was a missing Endif, one of those IF lines would down all the way to bottom of the program.

If a parentheses was missing between an If and an EndIF (or a Do and EndDo), perhaps that If/EndIF could be given a different color.

As I recall, the user was not bothered with picking/specifying the trace line color scheme or choice - it didn't matter. Its only job was to indicate, "... this starts here and ends there."

The simplicity - no, I'm not volunteering to add it to the compiler smile - is that there is no dependency on understanding the program logic. Each IF gets a trace, each Do gets a trace, etc. The innermost IF pairs with the first EndIF it encounters.

Just a thought.  Thank you for the consideration.