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

1.

INTRODUCTION

The evolutionary nature of computer programming has necessitated continual development and enhancement of programming languages. In an effort to make programming languages more responsive to such changes, a number of language extensibility schemes have been designed. Macro processor acts as a tool for programming language extensibility. A macro instruction is simply a notational convenience for the programmer. A macro represents a commonly used group of statements in the source programming language. The Macro processor replaces each macro instruction with the corresponding group of source language statements. This is called expanding the macros. Thus macro instructions allow the programmer to write a shorthand version of a program, and leave the mechanical details to be handled by the macro processor. For example, suppose that it is necessary to save the contents of all registers before calling a subprogram. On SIC/XE, this would require a sequence of seven instructions (STA, STB, etc.). Using a macro instruction, the programmer could simply write one statement like SAVEREGS. This macro instruction would be expanded into seven assembler language instructions needed to save register contents. The functions of a macro processor essentially involve the substitution of one group of characters or lines for another. Except in a few specialized cases, the macro processor performs no analysis of the text it handles. The design and capabilities of a macro processor may be influenced by the form of the programming language statements involved. However, the meaning of these statements, and their translation into machine language are of no concern whatsoever during macro expansion. This means that the design of the macro processor is not directly related to the architecture of the computer on which it is to run. The most common use of macro processor is in assembler language programming. We use SIC assembler language examples to illustrate most of the concepts being discussed in this project. However macro processors can also be used with High-level programming languages, Operating system command languages, etc. In addition there are general purpose macro processors that are not tied to any particular language.

Department of CSE, UVCE

June 2012

1|Page

Macro processor 1.1 DETAILED PROBLEM DEFINITION

Introduction

Processing of source code for a compiler requires many tasks before actual compilation of the program. Most of these tasks require refinement of code for the machine to understand. Programmers may write code to the best possible extent of their understanding and simplicity. Therefore, this requires a translation to more extensive code that the compiler can understand. Some of the problems faced by programmers in writing extensive code are explained in detail in the next few paragraphs. Code Readability: Very often while writing large chunks of code, there may be many places where code is repeated. Repetition of code can lead to confusion and reduce the readability of code. Maintaining readability is one of the main essences of proper programming. It is also the most difficult of tasks. Even with sufficient comments and spacing, it can still be hard to maintain readability. Furthermore, it is hard for humans to understand the same level of instructions as programming languages. The balance between human understanding and mnemonics is often blurred. It would be feasible for the programmer to replace large chunks of repeated code with a single code that has the same meaning. This would improve readability to a great extent and help with debugging purposes too. However, replacement text can sometimes cause more confusion if the programmer does not properly handle them. Function Overhead: Functions help solve this problem by sorting relevant code into one area. A program in sequence can call such a function, make it perform its task and return control to the line following the function call. However, functions (or methods) have a large overhead and can waste valuable processor time by repeatedly calling the same function. In fact there is nothing wrong with repeated code for the compiler. If the program execution requires repeated execution of codes, then functions will cause a significant loss of performance, especially if the functions carry small amounts of code in them. Therefore, functions should not be used to hold replacement code, but to hold relevant code that needs to be called only when required.

Department of CSE, UVCE

June 2012

2|Page

Macro processor Increased Processor Time:

Introduction

As already mentioned, repeated codes and calls for replacement can cause considerable processor wastage. Processing time is an important component of any system software. Applications can afford to suffer from processing time, but if system software largely suffers from processing time, then the whole setup is affected. Macros may increase compilation time by replacing text, including more text and submitting partial parts for compilation, but they help in producing more reliable code. Increased Spaghetti Code: The use of functions and redirection of control to other places to perform repeated functions results in what is called spaghetti code. This kind of code is rampant in the older top-bottom approach of programming languages, where instructions appear in sequence. Object-oriented programming techniques remove spaghetti code problems, but can only be implemented on object-oriented platforms. Moreover, even OOP concepts still suffer from readability problems. Programming languages such as C, where spaghetti code is all but common, and macros can help reduce this problem. Compilation Issues: To increase readability of code often, methods are written in various files and included wherever necessary. Unfortunately, these individual files cannot be compiled and then included during linking and execution. Therefore, this approach cannot be used unless macros are used to include the text from these files in the main source code file. This improves readability, reliability and debugging of the entire project.

Department of CSE, UVCE

June 2012

3|Page

Macro processor 1.2 BLOCK DIAGRAM:

Introduction

The following figure 1 is a block representation of the various actions that will take place for a fully-processed file with macros expanded and removed.

Input File

Scan file for macros

Macro Names Macro Definition

Extract macros with name and definition

Scan for macros names

Replace macro name with corresponding definition Processed File

Figure 1

Department of CSE, UVCE

June 2012

4|Page

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