Posts Tagged ‘intermediate code’

Common Business Oriented Language (COBOL) Source Code Generation

COBOL has been around for quite a number of years. Its use and popularity has given way to some of the newer languages. COBOL’s utilization is further enhanced by employing sub programming techniques that rely on the Linkage Section of COBOL.

COBOL source code generation is easily accomplished by using a symbolic stream generator with keyword replacements. To accomplish the COBOL source code generation first create an error free COBOL sub program containing the desired COBOL functionality. As an example we would have a COBOL program to operate on fixed length 80 column images. This technique is also known as Physical Sequential File Access. We then highlight various key portions of the COBOL source code so that they may be tokenized and marked for replacement by and intermediate code processor.

Typically the COBOL sub program would accommodate input as well as output thus allowing for one set of code to be used for both input and output of information.

The “RECORD CONTAINS 80 CHARACTERS” clause is changed to read “RECORD CONTAINS CHARACTERS”. The “” phrase becomes the token and by replacing it with the desired record length of 121 yields a source code program that will operate on logical records with a fixed length of 121 characters.

The FD name of the file description could be tokenized as and could be replaced with a desired descriptive name. This process is repeated for as many of the key elements of the COBOL sub program as required that yields the desired code flexibility.

Simply read the skeleton source code into memory and make the necessary replacements of the identified tokens and then save the updated source code to a unique file specification. Afterwards simply compile and link the newly created COBOL source code to yield the newly defined COBOL source code which meets the desired specifications. If the compiler resides on a remote computer simply File Transfer Protocol the source code to the target platform then proceed with the compile and link step. The majority of development is accomplished on the PC and the results are then uploaded to the mainframe for subsequent utilization.

Any processor or environment with the ability or change and replace the identified tokens can be used as the code generator.

Pascal my programming language of choice so much of the code generation work is performed on the windows platform then uploaded to the IBM Mainframe platform. Please keep in mind that I do have access to several PC based COBOL compilers.

Author: Arch Brooks
Article Source: EzineArticles.com
Provided by: WordPress plugin expert

Compiler Design – Choosing Intermediate Code

The basic principle of any compiler is to read the source file and to generate compiled code. In practice the compilation process is not so simple. There is a huge leap between the source code written in a high-level language and the desired target code for a particular platform. In general, each high-level statement will be translated to many low-level instructions for our target microprocessor.

In theory, it is possible to directly translate each source code statement to a sequence of microprocessor instructions which will perform the desired result. However, in practice it is better to perform the compilation in two steps. The first step is to process the source code and generate an intermediate code, and in the second step to process this code to generate the final executable code for our target microprocessor. There are many advantages in this approach.

It is a very good idea to have a target-independent intermediate code. This code is usually a description of the high-level statements with some simpler instructions that accurately represent the operations of the source code statements. This code will not execute in a real processor, it is only an internal representation of our high-level program. Since it uses simpler constructs than the high-level language it is much easier to determine the data and control flow. This is very important for optimization algorithms.

Target-independent intermediate code means that for each high-level language that needs to be supported we only have to write the first part of the compiler, the code generator is already written for the intermediate code which does not change. The same applies to the second part, the code generator. If we need to port our compiler to another platform, we only need to write a new code generator for the new processor.

The choice for intermediate code representation is not a simple task. We need to define a language that will be platform independent, will support all the features of desired processor families and will be easy to analyze for code optimizations.

Author: Igor Funa
Article Source: EzineArticles.com
Provided by: Latest trends in mobile phone