Вы находитесь на странице: 1из 38

1

After completing this learning unit, you will be able to

Compile basic programs on a TAFJ standalone area

Understand the compiler grammar levels

Execute TAFJ Runner

2
The various tafj tools are available as scripts in the
<TAFJ_HOME>/bin folder which inturn invoke corresponding
classes in the <TAFJ_HOME>/lib folder.
There is a compiler, runner and other helper tools. The
various distribution tools that come with TAFJ are mentioned
in the next slide.

3
4
To execute TAFJ tools
1. Navigate to the T24 folder in your TAFJ Dev area and double click on
the shortcut to the windows command processor cmd.exe. At the
CMD window, execute the tafj_Shell script as shown in the
snapshot, which sets the environment variables to execute tafj
commands.
2. If you have successfully completed your workshop in the last
session, you may also use your TAFJ Standalone area for executing
the TAFJ tools.
1. Work from <TAFJ_HOME>\bin in the command prompt
window. But you will have to set the necessary environment
variables everytime you launch the tools.
2. Or double click on Command prompt shortcut in the
TAFJWorkshop folder. This will launch a command prompt
window, setting all the necessary paths like JAVA_HOME,
TAFJ_HOME, ECLIPSE_HOME and ECLIPSE_DATA (for eclipse
workspace)

The folder <TAFJ_HOME>\bin, contain all the scripts for


executing the TAFJ tools. The scripts in turn invoke java classes
in the <TAFJ_HOME>\lib folder. These scripts have meaning only
in the standalone environment and will not be applicable on the
Application Server.

5
TAFJ Bootstrap is a batch file executed by all <script>.bat in bin to
initialize the environment variables that TAFJ uses. Among
several checks and settings done by this script, one essential
setting is the min and max memory setting for the JVM. Based on
your requirement you can adjust the memory setting in this
centralised file. Since all script files uniformly execute this batch
file, what you set here applies to all scripts.

-Xms, -Xmx are the JVM startup parameters. Suitably setting


them can optimize your JVM for performance. For Eg Xmx
defines the max memory size that your heap can reach for the
JVM. A low value can cause out of memory exceptions or a very
poor performance. -Xms sets the initial heap memory size for the
JVM. This means that when you start your program the JVM will
allocate this amount of memory instantly. This is useful if your
program will consume a large amount of heap memory right from
the start. This avoids the JVM to be constantly increasing the
heap and can gain some performance there. -XX:MaxPermSize is
to set the maximum Java Permanent Generation size. This
parameter will not be discussed here.

6
7
Write a simple basic routine using eclipse or notepad and
save it in the basic folder location that you have specified in
your .properties file. For e.g. - temn.tafj.directory.basic =
D:\TAFJWorkshop\T24\LOCAL.BP

8
The compilation of a basic program is done using tCompile .
tCompile is similar to EB.COMPILE in TAFC. It is a script that
in turn calls a java class called
com.temenos.tafj.compiler.tcompile.class kept in the
<TAFJ_HOME>/lib directory. The full path to the program to
compile must be provided. If the basic routine is present in
the BASIC path specified in the configuration, then the
configuration file can be specified in the options instead.
The syntax for using tCompile is - tCompile [-options]
[dirName] filelist
There are three options available –cf, -f, -h
-cf is used to specify a configuration file for the compilation
-f specifies a list of files to compile
-h is used to get help on the command.
Wild chars ('*'. '?') can not be used in the file name.

9
When you give the tCompile command, there is a lot which happens in the
background. What you pass to tCompile is a BASIC code and what comes out
as a result of compilation is a java Bytecode. First tCompile translates Basic to
Java. Understand, Basic is a script language which does not even have
datatypes for its variables and liberally allows usage of GOTO <labels>
whereas Java is a strongly typed object oriented language which does not
support GOTO statements. Such a translation should be deemed impossible.
However TAFJ achieves this humungous task by means of a translator which
was entirely developed in-house. The translator has three components
1. Lexer - The process of splitting characters into tokens is called lexing and is
performed by a lexer. So a basic command like CRT”HELLO” is split into
individual tokens by the lexer.
2. Parser – A parser assigns types to each token organizing them into an AST
(abstract syntax tree).
3. Tree walker – Replaces each type with a corresponding piece of java code
string which will eventually construct the java line of code. For e.g. Type
10 is replaced with ‘CRT(‘ and also appends ‘)’. Type 200 is replaced
with quotes – CRT(“ and ”)
This lexer-parser-tree walker are written in ANTLR and is referred to as the
translator which converts *.b to *.java. For every word, every syntax, every
exception (since basic has almost no rules and a developer can use the script
language in any way he desires) has a corresponding replacement. The .java
source code once it is generated is compiled using javac.
Note: *.b – all basic routines in TAFJ should have a ‘.b’ extension. It is not
mandatory currently, but will get enforced shortly.

10
Lets look at the compilation output report. tCompile uses the configuration file passed as
the parameter during compilation. If the –cf option is not used then the default
configuration file specified in the <Tafj_Home>/conf/.default file is used for compilation.
The below parameters in the display gets its value from this file.
Java Version is the java version that was used for compilation,
Java Home is the value set in the JAVA_HOME environmental variable.
Current Directory is the directory from which the tCompile was executed for
compilation.
tCompile –cf T24_Dev.properties EB.LOCKERS.b,
Looks for EB.LOCKERS.b in the current directory, if not found then it scans all the paths
specified as the Basic Source Dir. temn.tafj.directory.basic property in
T24_Dev.properties, holds all the basic source directories for this project.
Insert Source Dir is the path(s) where tCompile will check for INSERT files. The
property temn.tafj.directory.insert in the project files refers to insert directories for the
concerned project. If this property does not refer to any file paths, TAFJ will by default
take the Basic Source Dir path(s) for searching INSERT files.
Java Destination Dir (temn.tafj.directory.java) is the path where the java source will
get generated on compilation.
Classes Destination Dir(temn.tafj.directory.classes) is the path where the java
classes will get generated on compilation.
Max. Grammar Level/Min. Grammar Level are the grammar levels for the BASIC code
discussed in detail later.
Java Package (temn.tafj.package ) is the name of the package to which the java class
will belong to.
Status is the compilation status. And Total Time is the total time taken for compilation.

11
In the intermediary .java file, you can see that a class is
created for the basic EB.LOCKERS.b. This class extends
the main class jRuntime. The class jRuntime, part of
TAFJcore.jar(jar file which contains all the main T24 core
routines), contains the definitions of all the BASIC
KEYWORDS (OPEN, OCONV, …)

12
When a routine is compiled in TAFJ, it looks for
dependencies and automatically compiles all the dependent
codes too. In the program CALLER.RTN, there is a call to a
routine called MISSING.RTN. When we compile
CALLER.RTN, the compiler automatically tries to compile the
dependencies. Here MISSING.RTN is missing, hence it
generates a fake .class for the dependent missing routine,
reports this but compiles and generates the .class for
CALLER.RTN.
The fake class MISSING_RTN_cl.class is generated because
the routine MISSING.RTN is missing.

13
This is an example of Fake class generated because of an
erroneous dependency

14
In the syntax for using tCompile - tCompile [-options]
[dirName] filelist , the dirName is optional. If the dirName is
specified then all basic routines in that directory is compiled.
If the directory is not specified, TAFJ core will try to find the
file in the following order:
1) In the current directory
2) In the directories specified by
“temn.tafj.directory.basic”. This is a property in the property
file of the project.
If the directory is incorrect, TAFJ core will not compile and
display a message conveying this.

In the example shown, all the basic files in the directory


D:\TAFJWorkshop\T24\LOCAL.BP will get compiled.

15
You can see in the snapshot that all the files in the folder are
compiled at one go and the report is displayed.

16
Assume there are two property files T24_Dev and Tafj and the
following settings in your TAFJ area
T24_Dev.properties - temn.tafj.directory.basic = D:\src\T24_BP,
D:\SafeDeposit
Tafj.properties - temn.tafj.directory.basic = D:\src\T24_BP
.default - Tafj.properties
The search flow of the commands are listed below
1. Searches EB.LOCKERS.b in the current directory and if not
found uses temn.tafj.directory.basic of the property file specified
in .default
2. Searches EB.LOCKERS.b in the current directory and if not
found uses temn.tafj.directory.basic of T24_Dev.properties
3. Looks for EB.LOCKERS.b in D:\SafeDeposit, ignoring the
property file mentioned. If not found, then compilation fails.
4. Same as 3. Looks for EB.LOCKERS.b in D:\SafeDeposit and
compiles it.
5. Compiles all files starting with A in the directory mentioned
6. Compiles the relative directory and its subdirectories.

17
Excluding files from compilation
When compiling a directory you could also exclude some files
from the compilation by using the reject option.
tCompile [-cf <confFile>] [-reject rejectPattern]
<program_path_and_name>
Examples
tCompile -reject */EB.* D:\T24.BP – Compile everything in the
directory T24.BP but not the files starting with EB.
tCompile -reject */SUB/* D:\T24.BP - Compile everything in
the directory T24.BP but not the subfolder called SUB.
tCompile -reject */SUB/EB.* D:\T24.BP - Compile everything
in the directory T24.BP but not the files starting with EB in
subfolder SUB.
tCompile -reject “*/SUB/*|*/SUB2/*” D:\T24.BP - Compile
everything in the directory T24.BP but exclude subfolder SUB
and SUB2.
You need to specify your reject pattern between double
quotes when using multiple-criteria.

18
Lets consider a scenario where you have a random list of BASIC
codes to be compiled. There are two ways in which you can
compile them at one go.

Pass the list of file names to tCompile as shown in the snapshot


and all these files are compiled at one go.
Alternatively create a file with the list of programs to be compiled
as above:
Command to compile the list of BASIC files will be
tCompile –f <list_file_name>

19
When you compile using tCompile
1. It parses the code, checks for compilation errors, generates
java source code for the BASIC code and then compiles the java
code to generate a java class
2. The java source and the class files get created under
<tafj_home>\data\<projectname>\java\<package> and
<tafj_home>\data\<projectname>\classes\<package>. The basic
file names are appended with a _cl.java or _cl.class.
3. In TAFJ all java classes are grouped into a package specified
using temn.tafj.package property. Therefore the .java (and .class
files therefore) files automatically get created in the
com.temenos.t24 package.

The program EB.LOCKERS is first translated to


EB.LOCKERS_cl.java and compiled to EB.LOCKERS_cl.class

.java files are deleted on compilation . Set


temn.tafj.compiler.keep.java = true to keep the java source.

20
The name of the java class is defined by the Basic code
(SUBROUTINE, PROGRAM and FUNCTION), or if it doesn’t
exist, it is named by the name of the Basic file. Java doesn’t
support all the characters BASIC allows. The conversion rules for
the names (Program, Subroutine, Function, VAR, Label, equate
and insert are:
The ‘.’ are replaced by the ’_’
The ‘%’ are replaced by the ’_p_’
The ‘$’ are replaced by the ’_d_’
The ‘ ’ are replaced by the ’_s_’
The ‘(’ are replaced by the ’_l_’
The ‘)’ are replaced by the ’_r_’
The ‘!’ are ignored.
For example,
SLEEP.JBASE is a basic file (SUBROUTINE
!SLEEP$) is converted as SLEEP_d_.java
(SLEEP_d_.class)
BATCH.JOB.CONTROL is replaced by
BATCH_JOB_CONTROL
V$FUNCTION is replaced by V_d_FUNCTION

21
You must have noticed the term grammar levels in the
tCompile output. You will learn the purpose of grammar levels
and appreciate its benefits.

22
During the compilation, you’ll discover that there are different levels of
grammars, depending on the BASIC file you are compiling. These
“grammars” are different ways of translating the BASIC to JAVA,
depending on the quality of the BASIC CODE. There are 3 main
grammars levels on TAFJ: 2/3, 1 and 0
The grammar 2/3 implies that there are no control flow statements like
GOTO, ON … GOTO, RETURN TO, and labels especially inside the
below programming constructs (branching and looping constructs).
- IF … THEN … ELSE … END
- BEGIN CASE CASE … CASE … END CASE
- FOR … NEXT
- LOOP … WHILE | UNTIL test DO … REPEAT
The Grammar 2/3 is the most optimized, and the generated Java is well
formed and maintainable by a java developer.
The grammar 1 implies that there are no labels used in the given
constructs, but other control flow statements are present. This grammar
is not as optimized as the grammar 2/3, but can still be maintained.
The grammar 0 is due to the presence of a branching to a label within a
looping construct as shown in the snapshot. This grammar level exists
because the existing T24 basic code has lot of labels and GOTO’s.
Several T24 routines are compiled using this grammar lever.
In the sample code shown, the Label ‘LOCK.CONTROL.LIST ‘ is in a
looping construct. Thus this program will compile in grammar 0 only.
Labels can be removed with some intelligent code changes.

23
The grammar level used for EB.LOCKERS is 3 but for
BATCH.JOB.CONTROL the grammar level used for
compilation is 0. It means that the code of EB.LOCKERS is
very good and is easy to read and maintain, as grammar
level 3 is the most optimized of all grammar levels. Higher
grammar levels might be introduced in future. A code with
grammar level 0 is difficult to maintain.

24
The grammar levels can be set using two parameters in the
configuration file.
temn.tafj.compiler.grammar .maxlevel
temn.tafj.compiler.grammar.minlevel
E.g.
temn.tafj.compiler.grammar.maxlevel =3
temn.tafj.compiler.grammar.minlevel =0

Note: The temn.tafj.compiler.grammar level should always be


greater than temn.tafj.compiler.grammar.minlevel.

25
In the snapshot shwom, the min grammar level is set to 1 and
the max grammar level is 3. If we set the min grammar level
to 1, then some of our T24 basic code will not compile as
shown. Compiling BATCH.JOB.CONTROL with
temn.tafj.compiler.grammar.minlevel = 1 results in an error.
The compilation is cancelled, because the compiler expects
code with a minimum grammar level of 1.
BATCH.JOB.CONTROL has a grammar level of 0 due to the
presence of the label and branch statement inside a loop.
The same code compilation will be successful if the minimum
grammar was set to 0.

Note: It is safe to set minimum level as 0 and maximum level


as 3

26
If temn.tafj.compiler.translate.only is set to true, tCompile will
generate only the java files. The class files will not get
generated

If temn.tafj.compiler.parse.only is set to true, tCompile will not


generate any java source or class files. It will trace only for
errors in the basic code

During the code compilation, tCompile will check for any


dependencies, like a call to a SUBROUTINE or a DEFFUN
statement. If there is a call, then tCompile will automatically
find the dependencies and compile the code.

By setting temn.tafj.compiler.no.dependency the compiler


will not look for the dependency basic file. It should be a
already built or precompiled class.

27
The compilation workflow
When a tCompile command is executed, first the BASIC file
is analyzed, to determine its grammar level. Grammar
identifies the coding quality of the basic code. Then, the Java
file is generated in the directory specified by
‘temn.tafj.directory.java’ in the configuration file. The .java
file is compiled using the standard java compiler javac
included in the Java Development Kit (JDK). The resulting
java class is generated in the directory specified by the
‘temn.tafj.directory.classes’ property. Once the .class file is
generated, the .java file is deleted. To retain .java files, set
the property ‘temn.tafj.compiler.keep.java’ to true.

28
temn.tafj.compiler.grammar.maxlevel - the maximum grammar level
required by the compiler for the code to be compiled. It has to be greater
than or equal to minimum level grammar.
temn.tafj.compiler.grammar.minlevel - is the minimum grammar level
expected in the code to compile. If the quality of the code to be compiled
has a lesser level than what is set here, then the compilation is cancelled
temn.tafj.compiler.grammar.line.number – useful if you want to debug
the basic. Setting this property to true will generate the java source code
with line numbers.
temn.tafj.compiler.grammar.warning.depreciation - Generate traces
(logs) if a program cannot be compiled with the highest grammar level.
temn.tafj.compiler.grammar.warning.equate. - Generate traces if
duplicates are found in EQUATE statements added to your basic code.
temn.tafj.compiler.insert.name.any - As per standards, a Basic Insert
file starts with I_% like I_COMMON. With this property set to true, the
TAFJ compiler will accept any name as a $INSERT file.
temn.tafj.compiler.basic.encoding - By default the basic source file
encoding should be ISO-8859-1, but you may have to specify
another file encoding when running on specific platform, i.e. ibm zOs.

29
temn.tafj.package, - a java code is usually a part of a package. Since
basic code are converted to Java, they must be within a package. Specify
the package name here. By default com.temenos.t24 for T24 code.
temn.tafj.compiler.javac.options - The TAFJ Compiler use the javac to
compile the generated .java file. This property allows setting the javac
options. Type javac at the command prompt to see the complete list of
javac options.
temn.tafj.compiler.javac.compliance - defines the java version
compliance for use. For eg when set to 1.6, you will be able to execute the
generated code only on the targeted version 1.6 and later.
temn.tafj.compiler.translate.only - the compiler will generate the java
file but will not compile it.
temn.tafj.compiler.parse.only - The compiler will parse the basic code
without generating the java file. But BASIC language errors are displayed.
temn.tafj.compiler.no.dependency - when you compile a routine, the
dependent routines which are called from this routine are also
automatically compiled. Setting this property to true will ignore dependent
files.
temn.tafj.compiler.keep.java - To retain .java files, set the property to
true.

30
Let us see how to execute the program you compiled.

31
1.To execute a program in TAFJ, use the tool tRun. tRun is the
main entry point for running a program.
2.It is a script that invokes com.temenos.tafj.runtime.trun for
executing a BASIC program.
3.tRun is found under <tafj_home>\bin
4.The tRun command takes three parameters, the first parameter
is the option, the second parameter is the program name and the
third parameter could contain the arguments to the program at
runtime. If specified, these arguments will be given after the name
of the program. The option for the tRun is not a mandatory input.
There are two options available
-cf specifies the configuration file
-h to get help on the command
<parameters> used to pass runtime arguments
Syntax
tRun [-cf <confFile>] <BASIC program>
[<parameters>]

Parameters are also optional .

32
TAFJ manages the classloader … there are no classpaths to set i.e., in the CLASSPATH
environment variable. The order of loading the classpaths in TAFJ are as below

1. <TAFJ_HOME>\lib

2. <temn.tafj.directory.classes>

3. <temn.tafj.runtime.classpath> - list of jars or directories to load in the classloader, before

<tafj.home>/ext. For eg the Process workflow rules engine has an xml parser of a much older

version, which has to be loaded before the xml parser of the jdbc drivers in ext. Hence this

property.

4. <TAFJ_HOME>\ext

5. <temn.tafj.runtime.extended.classpath> - - list of jars or directories to load in the classloader,

after <tafj.home>/ext

6. <temn.tafj.directory.precompile>

The field separators, FM, VM, SM are double byte separators in TAFJ while in TAFC they are
maintained as single byte separators. The maximum number of characters that can be represented
with one byte is 256 characters, while two bytes can represent up to 65,536 characters.

33
Write a simple BASIC program

Override the autosetting to delete java files.

Compile the basic program. Open the java file generated.


Observe the naming convention of the .java and .class files.

Execute the basic program

34
EX is the Basic program to execute T24 classic. Therefore we can use
tRun to launch T24 classic.
However if you run tRun EX in a windows command window directly
you will not escape telnet characters. You need to run tRun inside a
telnet client. Using putty, a free telnet client, you can get a good
rendering.

1. On Windows 7, add a new user and set the users profile path to the
<tafj_home>/bin.
2. a. Start putty, select telnet protocol, type localhost as the hostname,
b. Remove in “Terminal” panel the text inside Answerback ^E field,
c. Select in “Terminal\keyboard” Ctrl-H for Backspace key and VT100
for Function key.
d. Click on Session and Save your session configuration
e. Click on open

[Note: Stop the jBase telnetd server from services.msc and start your
windows OS Telnet Server. Control Panel -> programs -> Turn windows
features on and off -> select Telnet Server and Telnet Client]

35
3. Login using the users credentials that you created … in
this case R14
4. Start your database from your tafj dev area. You will get
an error if your database is not started. Also ensure your
.properties file is pointing to this database.
4. Launch tRun EX.

36
Launch T24 Classic

37
In this learning units, you have learned :

Compile basic programs on a TAFJ standalone area

Understand the compiler grammar levels

Execute TAFJ Runner

38

Вам также может понравиться