[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [open-cobol-list] How does Cobol parse the Procedure Division ?
From: |
Wim Niemans |
Subject: |
Re: [open-cobol-list] How does Cobol parse the Procedure Division ? |
Date: |
Wed, 25 Sep 2013 15:28:21 +0200 |
A "normal" compiler should issue a warning that you have not reachable code
after a goto.
In this case there is a independent sentence saying "GO TO C-020.".
That having said, I would be terribly interested in a parser for the data
division. It is of incredible use to me.
Wim
Op 25 sep. 2013, om 15:15 heeft Dave Stratford het volgende geschreven:
>
> Patrick wrote:
>> Hi Everyone
>>
>> It's easy to see how Cobol can be parsed in all of the parts outside of
>> the PROCEDURE DIVISION, statements end with periods.
>>
>> I can't see how the compiler could understand what is going on in
>> PROCEDURE though. Every language I know of has some sort of character to
>> end a statement. It might be a non printable character but it's there.
>>
>> PROCEDURE ends in a period and paragraphs end in periods but if we have
>> a statement like this:
>>
>> MOVE foo TO moo
>>
>> I could see how the compiler would implicitly know that it ends one
>> token after TO but we can also have:
>>
>> MOVE foo TO moo koo boo
>>
>> Does the next reserved word that is not a part of the current sentence
>> signify an end to the current statement and the final period indicate
>> that there are no further statements coming ?
>>
>> If this is true, was it always this way. From what I understand it was
>> not.
>>
>> If this is true did it dramatically increase the complexity of the
>> compiler?
>>
>> Thanks
> Patrick,
>
> Full stops vs END-xxx changed at cobol 85. Cobol 74, and earlier, only has
> full stops, while END-xx were added at 85.
>
> Both have advantages and disadvantages.
>
> Imagine:
>
> IF A = B
> IF A > C
> MOVE 1 TO X
> ELSE
> MOVE 1 TO Y
> MOVE 1 TO Z
>
>
> Where does the final MOVE 1 to Z belong? What happens if you want the ELSE
> to be part of the IF A = B?
>
> When you ONLY had full stops, put a stop after the Y and the final move was
> independant of the IF's. Put it after the Z and it becomes part of the Z.
> An END-IF allows the programmer to be much more specific and flexible
> about things like this.
>
> An END-ADD, for example, is really only of use when you also use the ON
> OVERFLOW clause, which is why there is no END-MOVE, there is no ON OVERFLOW
> or equivalent. (I don't think!)
>
> At work I use a version of Cobol 74, so I don't have the END-xx, but it
> does mean I have to be a lot more careful about what I need to do.
>
> Personally I prefer full stops as it does mean I have to be a lot more
> precise, but there are cases when I would have liked to have had the
> inline perform that isn't available in cobol 74.
>
> That said, only yesterday, I had the following:
>
> C-010.
> MOVE I1-PROP-NO TO I4-PROP-NO.
> OBTAIN ANY R04-PROPERTY USING K4-PROP-NO
> ON DB-REC-NOT-FOUND
> DISPLAY "NO R04-PROPERTY FOR " I1-PROP-REF
> " CUSTOMER REF " I1-ACC-REF.
> GO TO C-020.
>
> MOVE I4-POST-CODE TO FAA-POST-CODE.
>
> WRITE FAA-EXT-REC.
>
> ADD 1 TO WC-WRITE-COUNT
> WC-CHECKPOINT-COUNT.
>
> C-020.
> IF WC-CHECKPOINT-COUNT NOT < WY-CHECKPOINT-LIMIT
> PERFORM Z-TAKE-CHECKPOINT.
>
> Can you work out why my program eventually fell over with a page lock
> table full error and an empty output file?
>
> Took me narly an hour and I lost even more hair!!!
>
> If anyone is interested, and I can find it, I had a cobol program that
> parses cobol programs to ensure they met the site coding standards of the
> site I was then working on. I myself wrote the data division parser. It's
> written in cobol 74, and parses cobol 74 programs. It would have found
> this fault.
>
> Dave
>
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
> _______________________________________________
> open-cobol-list mailing list
> address@hidden
> https://lists.sourceforge.net/lists/listinfo/open-cobol-list
Re: [open-cobol-list] How does Cobol parse the Procedure Division ?, Aries Software, 2013/09/25
Message not available
Re: [open-cobol-list] How does Cobol parse the Procedure Division ?, Dave Stratford, 2013/09/25
- Re: [open-cobol-list] How does Cobol parse the Procedure Division ?,
Wim Niemans <=
Re: [open-cobol-list] How does Cobol parse the Procedure Division ?, Fred Mobach, 2013/09/25