f



A COBOL program that parses its own source code

Written using Micro Focus COBOL 3.2.50 with extensions, the
program includes code for features not used by the program,
such as unary plus and minus, hexadecimal literals, etc.;
and does not process continuation lines, does not remove
inline comments, etc.
-----
       program-id. lex-scan.
       environment division.
       input-output section.
           select src-file assign to src-name
               organization line sequential.
           select token-file assign to "token.txt"
               organization line sequential.
       data division.
       file section.
       fd src-file
           record varying depending src-line-len.
       1 src-line pic x(160).
       fd token-file.
       1 token-rec.
        2 token-size pic z9.
        2 token-bar pic x.
        2 token-line pic x(77).
       working-storage section.
       1 comp.
        2 src-line-len pic 9(4).
        2 char-pos pic 9(4).
        2 an-lit-start pic 9(4).
        2 token-len pic 9(4).
       1.
        2 eof-src pic x value "n".
        2 an-delim pic x value space.
        2 token-sep pic x(2).
        2 pic-clause pic x value space.
       1 line-to-parse.
        2 occurs 0 to 160 depending src-line-len.
         3 char pic x.
       1 lex-token.
        2 occurs 0 to 80 depending token-len.
         3 tok-char pic x.
       procedure division.
       main section.
           move "lex-scan.cbl" to src-name
           open output token-file
           open input src-file
           perform until eof-src = "y"
               read src-file
               end
                   move "y" to eof-src
               not end
                   if src-line-len = 0
                     or src-line (7:1) = "*"
                   then
                       continue
                   else
                       move 8 to char-pos
                       if src-line-len > 72
                           move 72 to src-line-len
                       end-if
                       add 1 to src-line-len
                       move space to src-line (src-line-len:1)
           move function upper-case (src-line) to line-to-parse
                       perform parse-line
                       until char-pos > src-line-len
                   end-if
               end-read
           end-perform
           close src-file
           close token-file
           stop run
           .
       parse-line section.
           move 80 to token-len
           evaluate true
           when pic-clause not = space
               unstring line-to-parse delimited
                   ". " or all space
                   into lex-token delimiter token-sep
                   count token-len pointer char-pos
               move space to pic-clause
           when an-delim not = space
               unstring line-to-parse delimited an-delim
                   into lex-token delimiter token-sep
                   count token-len pointer char-pos
               move src-line (an-lit-start:token-len)
                   to lex-token
               if line-to-parse (char-pos:1) = an-delim
                   add 1 to token-len
                   move an-delim to lex-token (token-len:1)
                   add 1 to char-pos
               else
                   move space to an-delim
                   move space to token-sep
               end-if
           when other
               unstring line-to-parse delimited
                   all space or "," or ";" or """" or "'" or "&"
                   or "." or "X""" or "X'" or "(" or ")" or ":"
                   into lex-token delimiter token-sep
                   count token-len pointer char-pos
               if lex-token = "PIC" or "PICTURE"
                   move "y" to pic-clause
               end-if
           end-evaluate
           evaluate true
           when token-len = 0
               if token-sep = space or "," or ";"
                   continue
               end-if
           when token-len = 1
               if (lex-token = "+" or "-")
                 and token-sep = "("
               then
                   add 1 to token-len
                   move "(" to lex-token (2:1)
                   move space to token-sep
               end-if
               perform emit-lex-token
           when other
               if lex-token not = space
                   perform emit-lex-token
               end-if
           end-evaluate
           evaluate token-sep
           when space
           when ","
           when ";"
               continue
           when """"
           when "'"
               move token-sep (1:1) to an-delim
               move char-pos to an-lit-start
           when "X"""
           when "X'"
               move token-sep (2:1) to an-delim
               move char-pos to an-lit-start
           when other
               perform emit-token-sep
           end-evaluate
           .
       emit-lex-token section.
           move token-len to token-size
           move "|" to token-bar
           move lex-token to token-line
           write token-rec
           .
       emit-token-sep section.
           if token-sep (2:1) = space
               move 1 to token-size
           else
               move 2 to token-size
           end-if
           move "|" to token-bar
           move token-sep to token-line
           write token-rec
           .
       end program lex-scan.
-----
0
Rick
9/5/2013 7:46:46 PM
comp.lang.cobol 4278 articles. 1 followers. Post Follow

0 Replies
354 Views

Similar Articles

[PageSpeed] 18

Reply:

Similar Artilces:

guys Can you send me the Cobol Program/ Cobol code for this
Guys I need some tips from u r side=20 1. we need to create screen file, data file 2.read the data file in a loop populate it screen files 3. send the screen file & Read the screen file=20 I want this below data come on screen at end & ALSO 1. IT SHOULD BE [KEY BOARD OPERATED]NAVIGATED.not mouse operated 2 NEED TO RUN ON UNIX=20 3. WANT TO ACCESS Thru their [other] Machine thru TELNET=20 Requirement is to showout put=20 --------------------------------------------------------------------- 0123 BRIAN 2200 0124 WAYNE ...

Re: guys Can you send me the Cobol Program/ Cobol code for this
Raju, The HP3000 does not run Unix - its object programs are created for use by its own operating system: MPE-iX. It accepts input from the keyboard in 2 ways: Character-mode (one field at a time transmitted by pressing the 'Return' key), using the COBOL 'ACCEPT' statement or a 'REED' intrinsic - or - Block mode (the entire screen at one time, after the user presses the 'Enter' key), which HP calls a ViewPlus application. Code for the Block mode type of operation is quite complex - there is probably some third-party code which simplifies this...

Re: guys Can you send me the Cobol Program/ Cobol code for this #2
<<snip>> I am sure there are >many of us willing to do it at a cost. <<end snip>> I had previously responded (tongue in cheek) to this joker's earlier post= ings=20 about this kind of labor. As I expected I received no response. This guy in India just wants cheap (free) labor. Brian. On Tue, 3 Jul 2007 15:42:17 -0400, okappert <okappert@CANADA.COM>=20 wrote: >This requests goes beyond help. You are asking for someone on the list >to actually write the code for you. I, for one, don't mind helping out >if you have a p...

Calling a COBOL-DB2 program from a pure COBOL program.
Hi, An interviewer asks me if it is possible to Call a COBOL-DB2 program from a pure COBOL program? If possible, which utility do we need to use to execute it? I mean, we use IKJEFT01 to execute a COBOL-DB2 program. But, our case is different here because we are calling a COBOL-DB2 sub-program from a pure COBOL program. So, which utility to use and what is the procedure? I actually wrote a small main (COBOL) program and sub-program (COBOL-DB2) but don't know how to make use of it..........:-( Would anybody please explain. In article <1146655282.406710.104130@j73g2000cwa.googlegroup...

Can a COBOL batch program CALL to COBOL batch db2 program?
Actually I would like to know what additional JCL I will need if a COBOL non-DB2 program is calling to a COBOL/DB2 program. The original non-DB2 program is executed using: //STEP1 EXEC PGM=PROG1 I know I have to supply database name/plan to my program, but how? Another question: what happens is the PROG1 program is a DB2 program and is calling to another DB2 program with a different database and a different plan? What kind of JCL I need then? Do I need a special BIND? Thanks, Zalek "Zalek Bloom" <zalekbloom@hotmail.com> wrote in message news:e84e5f2f.031...

IBM COBOL
The following (not "official" as far as I know) statement appears in the recent "Cheryl's List #94 - 29 October 2004" "For example, we have been warned that ... the ISAM access method ... will no longer be supported as of z/OS 1.7." Should this be true, then this MIGHT impact some OS/VS COBOL customers who have remained on OS/VS COBOL (rather than migrating to VS COBOL II or later *because* of ISAM support). Personally, I don't know of any sites that haven't converted to VSAM by now, but who knows what actually exists in some shop somewhere. ...

need help to debug a cobol program with RM/COBOL-85
Hi, As it is wrote in the subject, i must debug a cobol program. I read the user's guide and i found that i should enter the D option in the RM/COBOL-85 Runtime Command to execute program for debugging. But, in fact, there are many long programs and I want set a breakpoint but i don't understand how to do this. The user's guide tells this : The syntax for the A command is as follows : A [line[+intraline][,[prog-name][,[count]]]] I tried to do : A 596,FGCENT this at the prompt but it doesn't work. Where is the problem ? Best regards Jerome On Tue, 05 Feb 2008 18:01:43 +0100, Jerome <j.aubert1@free.fr> wrote: >Hi, > >As it is wrote in the subject, i must debug a cobol program. >I read the user's guide and i found that i should enter the D option in >the RM/COBOL-85 Runtime Command to execute program for debugging. > >But, in fact, there are many long programs and I want set a breakpoint >but i don't understand how to do this. > >The user's guide tells this : >The syntax for the A command is as follows : >A [line[+intraline][,[prog-name][,[count]]]] > >I tried to do : >A 596,FGCENT >this at the prompt but it doesn't work. > >Where is the problem ? > >Best regards > >Jerome Please state OS and COBOL Version you are using. It may be possible that you can use the source debugger, and you wont have that type of issues. Frederico Fonseca ema il: frederico_fonseca a...

Converting Programs from HP3000 MPE Cobol to HP9000 UX Cobol
We are in the process of a huge conversion project and we keep finding little bugs on the MF-Cobol HP9000 side. For instance Reports are ok except the totals are off. It seems like an initialization problem, but I do not see anything obvious. I've been told MF Cobol is very strict in initialization, such as moving low-values to comp-3 fields. Does anyone have any ideas? Are any of these using Report Writer? In migrating those from a Honeywell to an IBM I had some problems where in I had to write DECLARATIVES to make the IBM side behave as the Honeywell system had (Mid-80s when I did this...

Where are spaces required in COBOL source code?
While playing around with the COBOL12 compiler (discussed elsewhere recently in this newsgroup), I ran into a few peculiarities. This is a DOS compiler that looks like a subset of 74 standard COBOL but has some extensions and some omissions. Its display is unusual since it uses a graphics mode to display text. Anyway I noticed two strange things. The compiler does not accept blank lines in source code and it requires a variable name to be separated by at least one space from the parentheses enclosing a subscript (or an expression denoting reference modification). An old CP/M era compiler also ...

Static analysis of COBOL source programs
Dear people, Greetings to everyone from Buenos Aires, After of a lot of years of developing I'm here as a COBOL QA Analyst. The Architecture and Infrastructure Managers are looking for programs that scan COBOL/400 source programs in search of metrics, definition errors or inconsistencies like as: Possible improvements in performances, (Eg use COMP-3 for arithmetic operations) duplicate code, coding standards (Eg use meaningful names for fields, align the IF / ELSE / END-ID / MOVE) logical coverage, (eg with EVALUATE WHEN OTHER ...) degree of complexity (Cyc...

COBOL indentation source code/algorithm
Hi ! Could anyone kindly provide me with a source code or an algorithm for indentation of an unindented COBOL program ? The input to the program will be an unindented COBOL program and the output will be an indented COBOL program. For example, all the "IF's" will be starting in a particular column, all "ELSE" in a specified column etc. Iam working on an OS/390 platform. I request you to kindly take out some time and please help me. Waiting for your reply, Regards, Tarun. -- Posted via http://dbforums.com On 8-Sep-2003, tarun_bhardwaj <member22201@d...

Cobol source code for a text adventure
A mine crawl written in Cobol can be obtained from http://members.cox.net/jdean284/Mines.htm. ...

Bind Native OSS code into COBOL program
Hello Friends, Is it possible to bind a Native OSS code as a library together into COBOL program? Am seeking the solution on both TNS/R and TNS/E system and am not using native cobol. I had some tries today - On TNS/E Compile OSS code as guardian type. This file code should be changed to 800 otherwise it cannot be executed. Then I tried use this oss program by "?SEARCH location of this oss code" in my cobol program I got the compilation error said like "file code should be 100" Then I change the oss code to be 100 and re-compiled, finnally get this "**** BINDER...

Alternative COBOL "telco" source program
(just sent to the IBM), FYI - some "new" timings with some minor (???) performance enhancements: With Calculations: Start-Time:17:07:07.70 End-Time:17:07:21.29 Without Calculations: Start-Time:17:14:31.06 End-Time:17:14:38.35 This reduces the calculation time from 23.08s to 13.59 - simply by switching to "native" binary temporary fields. (This uses NON-Standard - but relatively common COMP-5 syntax). The I/O time remains 7.29s - (compared to the original 8.31s run-time) This "additional" (alternative) source programs...

COBOL source code to create usersnames using SETUAI
Hi, I'm on vms 7.3-1 and need to start testing external authentication from our alpha's with Active directory, probably using something like ldap. I think my first hurdle is to create VMS usernames up to 32 characters long - using $setuai service. Its been a long time since I cut cobol code (cobol is the only compiler we have) and was wondering is some kind soul out there could throw me some code where they have done this before. Thanx, Martin. SETUAI cannot be used to create VMS accounts in SYSUAF. Martin wrote: > Hi, > > I'm on vms 7.3-1 and need to start testing ...

COBOL II to Enterprise COBOL
Hi, I need to change the some 1000 Program from COBOL II to Enterprise COBOL. What are the essential difference between COBOL II to Enterprise COBOL. How much can it affect my code ? (There are not much DB2,CICS in my code) Thanks, Dib If you are using the NOCMPR2 compiler option with your VS COBOL II compiler and you are using the LE run-time (with RES) then you will probably find that there is almost NO change required. (a few new reserved words, but not many). If you are using the VS COBOL II run-time and/or the NORES option, then you will need to do LOTS of testing for both change...

re: Alternative COBOL "telco" source program
From: Tim Challenger <"timothy(dot)challenger(at)apk(dot)at"> Date: Thu, 27 May 2004 07:57:52 GMT .. | Here the code to demonstrate a 1 statement solution, a 3 statement loop and | a 2 statement loop. So Mr Frank if you're listening, take down #18. | | It's complete except for Proc and end statements. | Compiler: VisualAge(TM) PL/I for Windows(R) V2.R1.08 .... | put edit(' one statement:')(skip, A); | i = searchr(trim(s), ' '); .. To be strictly correct, that should be trim(s, '') (also for the other examples). .. | put edit(substr(s, 1...

IBM Cobol and Unisys Cobol
Hello, I am new to this industry. I have started working on Unisys, can anybody please inform me the difference between Unisys cobol and IBM cobol. Thanks inqusite wrote: > Hello, > > I am new to this industry. I have started working on Unisys, can > anybody please inform me the difference between Unisys cobol and IBM > cobol. Well, a little more detail would help get you some answers. Are you using the Unisys A-series (NX) machine, or a 2200 (IX)? Are you using COBOL 74 or 85? -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ / \ / ~ Live from Montgomery, AL! ~ ~ / \/ o ~ ~ ~ / /\ - | ~ daniel@thebelowdomain ~ ~ _____ / \ | ~ http://www.djs-consulting.com ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~ ~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~ ~ h---- r+++ z++++ ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "Who is more irrational? A man who believes in a God he doesn't see, or a man who's offended by a God he doesn't believe in?" - Brad Stine On 4 Apr 2006 02:20:52 -0700, "inqusite" <indypoli@gmail.com> wrote: >I am new to this industry. I have started working on Unisys, can >anybody please inform ...

COBOL and code
WE have a program a programmer wrote for us. He is long gone. We hired another one but it appears the source for the file is misisng or he took it with him. I understand there are decompilers out there for this sort of thing. Is there a free or cheap one I could use. The environment is RISC6000 running AIX 5.1 I know about "de-compilers" for IBM mainframe (MVS) COBOL's - but none for AIX 5.1. -- Bill Klein wmklein <at> ix.netcom.com "scorpion53061" <scorpion_53061@nospamhereeveryahoo.com> wrote in message news:415db8d9$1@news.mcleodusa.net... &g...

COBOL compiler written in COBOL
Way back in 1974 I was the systems programmer in an all COBOL DP department, using an ICL 1902A mainframe, with punch card input and tape and disk storage. That was a small slow machine, and to compile a COBOL program could take up to half an hour. As usual there were many changes and file fixups to do, and these could be done only by writing a COBOL program especially for that purpose. Even for a small program it could take half a day to code, punch, list, check, compile, fix errors, recompile, and test. COBOL being a somewhat verbose language, the source was punched into cards by expe...

Cobol2Java: a Cobol to Java source code converter is available for evaluation
Automatic Cobol to Java source code migration tool, Cobol2Java, is available for trial from http://www.corporola.com to convert your golden Cobol code to universal Java code. New technologies, like object oriented for quality code, TCP/IP for Web and flexible database access, are supported without learning curves. Fast, no random error and low cost. Thomas Li Cobol + Java programmer Corporola Inc. Why does you want to translate COBOL into JAVA. They don't have the same target for me. BB ... a french COBOLIST -- Ben "Thomas A. Li" <tli@corporola.com> a �crit dans le...

Re: Alternative COBOL "telco" source program
"David Frank" <dave_frank@hotmail.com> writes: > > "William M. Klein" <wmklein@nospam.netcom.com> wrote in message > news:PCSoc.18996$V97.6991@newsread1.news.pas.earthlink.net... > > (just sent to the IBM), > > > > FYI - some "new" timings with some minor (???) performance enhancements: > > > > With Calculations: > > Start-Time:17:07:07.70 > > End-Time:17:07:21.29 > > > > Without Calculations: > > Start-Time:17:14:31.06 > > End-Time:17:14:3...

Ree: Alternative COBOL "telco" source program
>robert.deletethis@wagner.net (Robert Wagner) wrote >>If 'someone else calls your .dll' and gets your data values then that >>would be a serious issue, but what systems would this occur with ? > Windows and Unix systems. The question was "_and_gets_your_data_". You seem to have some strange ideas about what happens in a Cobol run-unit. While the .dll or .so contains the code and the initial values for W-S the actual W-S and L-S is created in the run-unit's address space. If it abends then the data areas disappear too. If two separate run units on...

re: Alternative COBOL "telso" source program
From: Tim Challenger <"timothy(dot)challenger(at)apk(dot)at"> Date: Thu, 27 May 2004 07:57:52 GMT .. | Here the code to demonstrate a 1 statement solution, a 3 statement loop and | a 2 statement loop. So Mr Frank if you're listening, take down #18. | | It's complete except for Proc and end statements. | Compiler: VisualAge(TM) PL/I for Windows(R) V2.R1.08 | | dcl s char(80) | init("The quick brown fox jumps over the lazy dog's back."); | dcl i fixed bin(31) init(0); | | put edit(' one statement:')(skip, A); | i = searchr(trim(s), &...

Web resources about - A COBOL program that parses its own source code - comp.lang.cobol

Program - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Matthew Guy warns against expanding Safe Schools program to all Victorian classrooms
... MPs also weighed into the Safe Schools debate. State Liberal leader Matthew Guy has backed Malcolm Turnbull's review of the Safe Schools program ...

UN slaps new sanctions on North Korea over its nuclear program
... have been added to a UN blacklist. United Nations: North Korea faces harsh new UN sanctions to starve it of money for its nuclear weapons program ...

The Top Cable News Programs for February, 2016 Are…
... viewers). O’Reilly averaged 3.2 million total viewers, up +8 percent vs. last year. Because this ranks regularly-scheduled cable news programs, ...

Brazil’s Distributed Electricity Generation Program Takes Effect Today
A historic net metering revision for distributed electricity is now in play in Brazil. Planned revisions to Brazil’s net metering program for ...

New Valve program drops Steam bundle prices to account for already-owned games
... to take advantage of the savings that game bundles offer without possibly necessitating the purchase of duplicate licenses. This program introduces ...

Budgeting For Federal Lending Programs Is Still A Mess
On Monday, the Government Accountability Office (GAO) defended the current method for budgeting for federal lending programs, known as “credit ...

Seattle lawmakers split over whether to buy out ‘insolvent’ bike-share program for $1.4M
A Pronto bike-share station at the University of Washington student gym. The fate of Seattle’s bike-share program will be decided later this ...

All of Star Trek: Enterprise Was Really Just Will Riker's Holodeck Program
As with any franchise that has been around 50 years, Star Trek has a number of plot holes and continuity errors. The last show, Enterprise , ...

'Hack the Pentagon' and Get Paid Legally in New Program
... pay you to break into some government systems. Today Defense Secretary Ash Carter announced the military’s first-ever “Hack the Pentagon” program ...

Resources last updated: 3/7/2016 4:21:56 AM