This is a very simple parser that parses Natural-ADABAS programs. The NATURAL source program is parsed at HEADER, TITLE, DETAIL, CODE_LINE, DEFINE_LINE level.
The first example will only check the type of the lines and verify whether it is one of these types. The JavaCC jj file follows.
options {
IGNORE_CASE = true;
DEBUG_PARSER = false;
DEBUG_LOOKAHEAD = false;
DEBUG_TOKEN_MANAGER = false;
LOOKAHEAD = 1;
FORCE_LA_CHECK=true;
}
PARSER_BEGIN(ProcessFile)
/** Simple Java Parser. */
public class ProcessFile
{ /** Main entry point. */
public static void main(String args[]) throws ParseException {
ProcessFile parser = new ProcessFile(System.in); parser.Input();
}
}
PARSER_END(ProcessFile)
TOKEN: {
<CR_LF: "\r\n">
| <HEADER: ("*H**") (<GENERAL>)* <CR_LF>>
| <TITLE: ("*C**") (<GENERAL>)* <CR_LF>>
| <DETAIL: ("*D") (<GENERAL>)* <CR_LF>>
| <CODE_LINE: ("*S**" <LINE_NUM> (<GENERAL>)* <CR_LF>)>
| <#LINE_NUM: (["0"-"9"])(["0"-"9"])(["0"-"9"])(["0"-"9"]) >
| <DEFINE_LINE: ("*S****" ("DF" | "DRR" | "DFR" | "C" | "DV" | "DD" | "V" "DFR" | "DRR" | "DSR" |"HS" | "I") (<GENERAL>)* <CR_LF>)>
| <END_STATEMENT: "*E" <CR_LF>>
| <#GENERAL: (["a"-"z","A"-"Z", "0"-"9", "(", ")", "[", "]", ":", "\'", "*", "|", ";", "%", " ", "-", "/", ".", "=", "#", "@", "+", "_", "<", ">", "^", "$", "?", "&", ",", "ı", "İ", "ş", "Ş", "ü", "Ü", "ç", "Ç", "ğ", "Ğ", "ö", "Ö"])>
}
/** Root production. */
void Input() : {
System.out.println("Parsing started!");
}
{
( (<HEADER> )
| (<TITLE> )
| (<DETAIL> )
| <CODE_LINE>
| <DEFINE_LINE> )*
<END_STATEMENT>
<EOF>
{System.out.println("Parsing is completed with success!");} }
The input lies at the bottom.
The output:
*C** ACCOUNT ACCB001 F S
*D01NAT2303F ACCOUNT ACCB001 DBA0240 DBA0240 0000 S
*D02 2007072602061052007072602061050000009132
*D03MVS/ESA CICS NATP
*D04
*S**0010************************************************************************
*S**0020* SYSTEM NAME : ACCOUNT *
*S**0030* PROGRAM NAME : ACCB001 *
*S**0040* PROGRAMER NAME : MAGED EL-SHARKAWY *
*S**0050* DATE WRITTEN : SEP-29-1999 *
*S**0060* DATE UPDATED : *
*S**0070************************************************************************
*S**0080* P U R P U S E : THIS PROGRAM IS REPORT ABOUT MONTHLY REPORT *
*S**0090************************************************************************
*S**0100* LANGUAGE NAME : NATURAL 2.2 *
*S**0110* GLOBAL DATA AREA : ACCG001 *
*S**0120* SCREEN NAME : ACCO001 *
*S**0130* CHAINED PROGRAMS : ACCP950 *
*S**0140************************************************************************
*S**0150DEFINE DATA
*S**0160 GLOBAL USING ACCG001
*S**0170 LOCAL USING ACCL001B
*S**0180END-DEFINE
*S**0190*
*S**0200FORMAT PS=62 LS=132
*S**0210INPUT #PARM
*S**0220EXAMINE #PARM FOR '@' REPLACE WITH ' '
*S**0230CALLNAT 'LANGCHK' +LANG +HDATE
*S**0240*
*S**0250MOVE #MONTH-DESC(#MONTH) TO #MONTH-DES
*S**0260MOVE #CHAP-DESC(#CHAPTER) TO #BAB-DESC
*S**0270AT TOP OF PAGE
*S**0280 WRITE NOTITLE NOHDR USING MAP 'ACCO001'
*S**0290END-TOPPAGE
*S**0300*
*S**0310MOVE #SIT TO #SITE1 #SITE2
*S**0320MOVE #YEAR TO #C-YEAR1 #C-YEAR2
*S**0330MOVE 999999 TO #C-NO2
*S**0340MOVE 999999999999 TO #ACNT-ACC2
*S**0350*
*S**0360IF #CHAPTER = 1
*S**0370 FIND TBBUDDST-V WITH DST_YEAR = #YEAR-SIT
*S**0380 SORTED BY DST_ACNT_G
*S**0390 WHERE DST_CHAPTER = #CHAPTER
*S**0400 AND DST_ITEM > 0
*S**0410 AND DST_ELEMENT = 0
*S**0420 AND DST_SUB_ITEM = 0
*S**0430 AND DST_DEPT_CODE = 0
*S**0440 MOVE DST_CHAPTER TO #ACNT-CHAPTER
*S**0450 #ACNT-CHAPTER2
*S**0460 MOVE DST_ITEM TO #ACNT-ITEM
*S**0470 #ACNT-ITEM2
*S**0480 MOVE DST_SHORT_NAME TO #ACNT-DESC
*S**0490 MOVE DST_PRIMARY TO #ACNT
*S**0500 ADD DST_PRIMARY TO #ACNT-T
*S**0510 PERFORM READ-JDT
*S**0520 WRITE NOTITLE NOHDR USING MAP 'ACCO001A'
*S**0530 RESET #ACNT #ACNT-CHAPTER #ACNT-DESC #ACNT-ELEMENT #ACNT-ITEM
*S**0540 #ACNT-SUB-ITEM #CURRENT #PAST #TOTAL
*S**0550 END-FIND
*S**0560 WRITE NOTITLE NOHDR USING MAP 'ACCO001B'
*S**0570 RESET #ACNT-T #CURRENT-T #PAST-T #TOTAL-T
*S**0580END-IF
*S**0590IF #CHAPTER = 2
*S**0600 FIND TBBUDDST-V WITH DST_YEAR = #YEAR-SIT
*S**0610 SORTED BY DST_ACNT_G
*S**0620 WHERE DST_CHAPTER = #CHAPTER
*S**0630 AND DST_ITEM > 0
*S**0640 MOVE DST_CHAPTER TO #ACNT-CHAPTER
*S**0650 #ACNT-CHAPTER2
*S**0660 MOVE DST_ITEM TO #ACNT-ITEM
*S**0670 #ACNT-ITEM2
*S**0680 MOVE DST_ELEMENT TO #ACNT-ELEMENT
*S**0690 #ACNT-ELEMENT2
*S**0700 IF DST_ITEM = 206 OR = 208 OR = 222
*S**0710 IF DST_ELEMENT = 0
*S**0720 OR NOT DST_SUB_ITEM = 0
*S**0730 OR NOT DST_DEPT_CODE = 0
*S**0740 ESCAPE TOP*S**0750 END-IF
*S**0760 PERFORM READ-JDT
*S**0770 ELSE
*S**0780 IF NOT DST_ELEMENT = 0
*S**0790 OR NOT DST_SUB_ITEM = 0
*S**0800 OR NOT DST_DEPT_CODE = 0
*S**0810 ESCAPE TOP
*S**0820 END-IF
*S**0830 MOVE 999 TO #ACNT-ELEMENT2
*S**0840 PERFORM READ-JDT
*S**0850 END-IF
*S**0860 MOVE DST_SHORT_NAME TO #ACNT-DESC
*S**0870 MOVE DST_PRIMARY TO #ACNT
*S**0880 ADD DST_PRIMARY TO #ACNT-T
*S**0890 WRITE NOTITLE NOHDR USING MAP 'ACCO001A'
*S**0900 RESET #ACNT #ACNT-CHAPTER #ACNT-DESC #ACNT-ELEMENT #ACNT-ITEM
*S**0910 #ACNT-SUB-ITEM #CURRENT #PAST #TOTAL
*S**0920 END-FIND
*S**0930 WRITE NOTITLE NOHDR USING MAP 'ACCO001B'
*S**0940END-IF
*S**0950*
*S**0960IF #CHAPTER = 3
*S**0970 FIND TBBUDDST-V WITH DST_YEAR = #YEAR-SIT
*S**0980 SORTED BY DST_ACNT_G
*S**0990 WHERE DST_CHAPTER = #CHAPTER
*S**1000 AND DST_ITEM > 0
*S**1010* AND DST_ELEMENT = 0
*S**1020* AND DST_SUB_ITEM = 0
*S**1030 AND DST_DEPT_CODE = 0
*S**1040 MOVE DST_ELEMENT TO #DST-ELEMENT
*S**1050 MOVE DST_ITEM TO #DST-ITEM
*S**1060 RESET #COUNT
*S**1070 PERFORM READ-DST
*S**1080 IF #COUNT = 1 AND DST_ELEMENT = 0
*S**1090 ESCAPE TOP
...
...
...
...
*S**2560END-FIND
*S**2570**************
*S**2580END-SUBROUTINE
*S**2590**************
*S**2600*
*S**2610END
*C** ACCOUNT ACCB002 F S
*D01NAT2303F ACCOUNT ACCB002 DBA0240 DBA0240 0000 S
*D02 2007072602061262007072602061260000005996
*D03MVS/ESA CICS NATP
*D04
*S**0010************************************************************************
*S**0020* SYSTEM NAME : ACCOUNT *
*S**0030* PROGRAM NAME : ACCB002 *
*S**0040* PROGRAMER NAME : BANDER *
*S**0050* DATE WRITTEN : DEC-11-2000 *
*S**0060* DATE UPDATED : *
*S**0070************************************************************************
*S**0080* P U R P U S E : THIS PROGRAM IS REPORT ABOUT MONTHLY REPORT *
*S**0090************************************************************************
*S**0100* LANGUAGE NAME : NATURAL 2.2 *
*S**0110* GLOBAL DATA AREA : ACCG001 *
*S**0120* SCREEN NAME : ACCO002 *
*S**0130* CHAINED PROGRAMS : ACCP950 *
*S**0140************************************************************************
*S**0150DEFINE DATA
*S**0160 GLOBAL USING ACCG001
*S**0170 LOCAL USING ACCL002B
*S**0180END-DEFINE
*S**0190*
*S**0200FORMAT PS=62 LS=132
*S**0210INPUT #PARM
*S**0220EXAMINE #PARM FOR '@' REPLACE WITH ' '
*S**0230CALLNAT 'LANGCHK' +LANG +HDAT
*S**0240*
...
...
...