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.

Field Detail

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.

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.

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.

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.

Constructor Detail

Preprocessor

public Preprocessor()
Public empty constructor.

Method Detail

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 :

Parameters:
args - Command-line arguments.