CommandExtractor is the simpler Progress 4GL parser used internally by Justus tools. It uses some
basic rules to strip an input source file into generic statements.
The table bellow shows a sample source file processed by CommandExtractor.
| Line | Code |
|---|---|
| 1 | /****************************************************** ** This is a sample source code for testing parser. ** Author: Flavio Eduardo de Córdova ******************************************************/ |
| 6 |
DEFINE TEMP-TABLE ttLogging NO-UNDO
FIELD custName AS CHARACTER
FIELD callDuration AS DECIMAL
INDEX custName
custName. |
| 12 |
DEFINE TEMP-TABLE ttSumary NO-UNDO
FIELD custName AS CHARACTER
FIELD totalDuration AS DECIMAL. |
| 16 | RUN generateRandomData. |
| 17 | RUN sumarize. |
| 18 | RUN cleanUp. |
| 21 | PROCEDURE generateRandomData PRIVATE: |
| 22 |
&SCOPED-DEFINE EXTENT_SIZE 5 |
| 23 |
DEFINE VARIABLE cAvailableCustomers AS CHARACTER EXTENT {&EXTENT_SIZE} NO-UNDO
INITIAL ["~"cust1~"", '"cust2"', "'cust3'", '~'cust4~'', "cust5"]. |
| 26 |
DEFINE VARIABLE iEntries AS INTEGER NO-UNDO. |
| 28 |
generation: |
| 29 |
DO iEntries = 1 TO 100: |
| 30 |
CREATE ttLogging. |
| 31 |
ASSIGN
ttLogging.custName = cAvailableCustomers[(iEntries MOD {&EXTENT_SIZE}) + 1]
ttLogging.callDuration = RANDOM(1, 1500) / 100. |
| 34 |
END. |
| 35 | END. |
| 37 | PROCEDURE sumarize PRIVATE: |
| 38 |
DEFINE BUFFER ttLoggingBuffer FOR ttLogging. |
| 39 |
FOR EACH ttLoggingBuffer
BREAK BY ttLoggingBuffer.custName: |
| 41 |
IF FIRST-OF(ttLoggingBuffer.custName) THEN DO: |
| 42 |
CREATE ttSumary. |
| 43 |
ttSumary.custName = ttLoggingBuffer.custName. |
| 44 |
END. |
| 45 |
ttSumary.totalDuration = ttSumary.totalDuration + ttLoggingBuffer.callDuration. |
| 46 |
END. |
| 47 | END. |
| 49 | PROCEDURE cleanUp PRIVATE: |
| 50 |
FOR EACH ttSumary
EXCLUSIVE-LOCK: |
| 52 |
DELETE ttSumary. |
| 53 |
END. |
| 55 |
FOR EACH ttLogging
EXCLUSIVE-LOCK: |
| 57 |
DELETE ttLogging. |
| 58 |
END. |
| 59 | END. |
The table below shows the Java code used to extract Progress statements:
import net.cordova.justus.progressparser.*;
import java.io.*;
public class MyTest implements CommandListener {
public static void main(String args[]) {
File f = new File(args[0]);
try {
CommandExtractor extractor = new CommandExtractor(f);
extractor.addCommandListener(new MyTest());
extractor.analiseCode();
}
catch(Exception e) {
Sysout.err.println("Error: " + e.getMessage());
}
}
public void commandRead(ProgressStatement command) {
System.out.println(command);
}
} |