testparser
Class Preprocessor
- public class Preprocessor
- This class converts a COBOL 85 fixed-format source into a free format source. It also processes the REPLACE and COPY statements, and converts compiler directives to comments.
- Author:
- Bernard Pinon
Copyright (c) Bernard Pinon 2002
This file can be freely redistributed under the terms of the LGPL licence published by the Free Software Foundation.
FORMAT_FIXED
public static final int FORMAT_FIXED
- Indicates that the input format is fixed - this is the standard ANSI format, inspired by punched cards. Each line must have exactly 80 characters.
- Col 1 to 6 (included) : comments - used to number cards
- Col 7: indicator field
- Col 8-12 : Area A
- Col 13-72 : Area B
- Col 73-80 : comments
FORMAT_VARIABLE
public static final int FORMAT_VARIABLE
- Indicates that the format is variable. This is used by the Fujitsu-Siemens compiler for instance. In this format, lines can have a variable length.
- Col 1 to 6 (included) : comments
- Col 7: indicator field
- Col 8-12 : Area A
- Col 13-80 : Area B
FORMAT_TANDEM
public static final int FORMAT_TANDEM
- Indicates that the format is the one used on HP-Compaq Non-stop systems, also known as "Tandem" systems. This is similar to the variable format, but without the first six comment characters.
- Col 1: indicator field
- Col 2-6 : Area A
- Col 7-80 : Area B
source_format
private int source_format
- The format currently in use.
source_path
private File source_path
- The path of the source file. We assume that all copy-books will reside in the same directory.
input
private BufferedReader input
- A reader for the fixed format COBOL 85 source.
output
private PrintWriter output
- A writer for the free format COBOL 85 source.
line
private String line
- The current source line.
line_number
private int line_number
- The current line number, for error messages.
indicator_field
private char indicator_field
- The indicator field of the current line.
replace
private HashMap replace
- The REPLACE substitution map.
DELIMITERS
private static final String DELIMITERS
- The delimiters used to parse the source line for REPLACE/COPY.
include_debug_lines
private boolean include_debug_lines
- If true, we include debugging lines in the resulting source.
Preprocessor
public Preprocessor()
- Public empty constructor.
skipDelimiters
private final String skipDelimiters(StringTokenizer st)
- Skips all delimiters in the parsed line.
- Parameters:
st
- a StringTokenizer.
- Returns:
- the next significant token or an empty string.
processCopy
private final void processCopy(StringTokenizer st)
- Processes the COPY statement.
- Parameters:
st
- a StringTokenizer.
processReplace
private final void processReplace(StringTokenizer st)
- Processes the REPLACE statement.
- Parameters:
st
- a StringTokenizer.
removeTrailingSpaces
private static final String removeTrailingSpaces(String line)
- Removes the trailing spaces on a line. Used to save some space.
- Parameters:
line
- a String.
- Returns:
- the string without trailing spaces.
processCopyReplace
private final void processCopyReplace(String line)
- Processes a COBOL line, traping COPY/REPLACE statements, and making the substitutions required by REPLACE.
- Parameters:
line
- a String
normalizeLine
private final String normalizeLine(String line)
- Normalize an input line to the TANDEM format.
- Parameters:
line
- the input line.
- Returns:
- a COBOL source line in Tandem format.
outputAsComment
private final void outputAsComment(String line)
- Outputs a line (which is not necessary a comment) as a comment.
- Parameters:
line
- the line.
outputComment
private final void outputComment(String line)
- Outputs a comment line.
- Parameters:
line
- the line.
preprocessMainline
private final void preprocessMainline()
- The preprocessor mainline, called recursively when processing COPY.
- Throws:
IOException
-
preprocess
public void preprocess(String in_path,
String out_path)
- The preprocessor main entry point.
- Parameters:
in_path
- Path to input file.
out_path
- Path to output file.
getLineNumber
public int getLineNumber()
- Returns:
- the last line number.
getSourceFormat
public int getSourceFormat()
- Returns:
- the source format.
setSourceFormat
public void setSourceFormat(int source_format)
- Sets the source format.
- Parameters:
source_format
- the new format.
includesDebugLines
public boolean includesDebugLines()
- Returns:
- true if we include debug lines
setIncludeDebugLines
public void setIncludeDebugLines(boolean include_debug_lines)
- Parameters:
include_debug_lines
- if true, includes lines marked with "D".
displayProgramUsageAndExit
private static final void displayProgramUsageAndExit()
- Display program usage and exit. Why do I have this impression of repeating myself?
main
public static void main(String[] args)
- A simple mainline.
Usage : java Preprocessor [<options>]<in_path> [<out_path>]
where :
<options>
: preprocessor options :
Input format option : -F (fixed) -V (variable) -T (tandem)
Debug option : -D (include debug lines) <in_path>
: COBOL 85 source path. <out_path>
: output path. If omitted, stdout is used.
- Parameters:
args
- Command-line arguments.