60
Macro Processor Chapter-1 Introduction 1.1. Problem Definition Processing of source code for a compiler requires many tasks before actual compilation of the program. Most of theses 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, thisrequires a translation to more extensive code that the compiler can understand. Some of the problems faced by programmers in writing extensive code are explained indetail in the next few paragraphs. 1.1.1 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 also is the most difficult oftasks. 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 Dept of ISE, RVCE 2014-15 Page 1

Macro Processor

Embed Size (px)

DESCRIPTION

Macro Processor & Respective code

Citation preview

Macro Processor

Macro Processor

Chapter-1 Introduction

1.1. Problem Definition

Processing of source code for a compiler requires many tasks before actual compilation of the program. Most of theses 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, thisrequires a translation to more extensive code that the compiler can understand. Some of the problems faced by programmers in writing extensive code are explained indetail in the next few paragraphs.

1.1.1 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 also is the most difficult oftasks. 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. 1.1.2 Function Overhead: Functions help solve this problem by sorting relevant code into one area. A program in sequence can call sucha 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 usedto hold replacement code, but to hold relevant code that needs to be called only when required.

1.1.3 Increased Processor Time: 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. 1.1.4 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.

1.2 Basic Definitions1.2.1 Simple Callable Macros: Macros must first be defined, before they can be called in a program. A simple macro definition consists of the macro name, which can be defined with the keyword MACRO, the macro body, and a final ENDM (end macro) instruction. MACRO . . ENDM

The macro name must be a valid, unique symbol. It cannot be redefined later. Keywords cannot be used as macro names. The macro body may comprise any number of lines. Body lines may be all kinds of assembler instructions, pseudo instructions, controls, meta instructions, macro calls and even further macro definitions.The macro body and the whole macro definition is terminated with the ENDM instruction.Macros must be defined, before they can be called. Forward references to macros are not allowed. Once defined, a macro can be called by its name in the subsequent program as often as desired. Whenever a macro is called, the macro body will be "inserted" into the program and then assembled as normal source lines. This process is called macro expansion.

1.2.2 Macro ParametersCallable macros may have parameters, to allow more flexible use. The names of the formal parameters are specified in the macro definition behind the keyword MACRO, separated by commas. All parameter names of a macro must be different, valid symbols. Keywords cannot be used as parameter names. Macros may have any number of parameters, as long as they fit on one line. Parameter names are local symbols, which are known within the macro only. Outside the macro they have no meaning! MACRO , , ... , . . ENDMWhen called, actual arguments can be passed to the macro. The arguments must be separated by commas. Valid macro arguments are1. arbitrary sequences of printable characters, not containing blanks, tabs, commas, or semicolons2. quoted strings (in single or double quotes)3. single printable characters, preceded by '!' as an escape character4. character sequences, enclosed in literal brackets < ... >, which may be arbitrary sequences of valid macro arguments (types 1. - 4.), blanks, commas and semicolons5. arbitrary sequences of valid macro arguments (types 1. - 4.)6. expressions preceded by a '%' character1.2.3 Macro OperatorsThere are some special control characters, which are very useful for macro definition, call and expansion:;;Macro commentaryNormally, comments in body lines are also contained in the expanded lines. If a commentary begins with ';;' however, it is not stored during macro definition. Therefore, it doesn't consume memory space, and appears in the list file in the macro definition only, but not in the expanded lines.

!Literal operatorIf the escape character '!' precedes another printable character in a macro argument, the assembler is forced to treat that character literally. This means it will be passed to the macro, even if it is a control character, while the literal operator itself is removed.

Literal bracketsIf a macro argument is intended to contain separation or control characters, it must be enclosed in literal brackets < ... > to pass it to the macro as one argument string, while the outermost pair of brackets is removed. Literal brackets can be nested to any depth.

%EvaluationIf a macro argument is preceded by the evaluation operator '%', it is interpreted as an expression, which will be evaluated before it is passed to the macro. The actual argument string will not be the expression itself, but a decimal ASCII representation of its value. The expression must be known onpass 1.

&SubstitutionThe '&' character separates parameter names (local symbols) from surrounding text. Outside quoted strings and commentary it serves only as a general separation character. This applies always when a local symbol directly precedes or follows another alphanumeric string. Inside quoted strings and commentary, a local symbol must be preceded by '&' if it is to be substituted there. During every macro expansion, the assembler removes exactly one '&' from every sequence of '&' characters. This allows for example, to define a nested macro inside a macro body, which also uses the substitution operator '&': one writes simply '&&'!

1.2.4 Nested Macro DefinitionsA macro body may also contain further macro definitions. However, these nested macro definitions aren't valid until the enclosing macro has been expanded! That means, the enclosing macro must have been called, before the nested macros can be called.Example 1:A macro, which can be used to define macros with arbitrary names, may look as follows: DEFINE MACRO MACNAME MACNAME MACRO DB 'I am the macro &MACNAME.' ENDM ENDM1.2.5 Nested and Recursive Macro CallsMacro bodies may also contain macro calls, and so may the bodies of those called macros, and so forth. If a macro call is seen throughout the expansion of a macro, the assembler starts immediately with the expansion of the called macro. For this, its its expanded body lines are simply inserted into the expanded macro body of the calling macro, until the called macro is completely expanded. Then the expansion of the calling macro is continued with the body line following the nested macro call.1.3. Block Diagram

The following is a block representation of the various actions that will take place during macro expansion.

1.a Block representation of macro expansion

Chapter-2 Theory and Concepts of Macro Processor

2.1 IntroductionMacro processor replaces each macro instruction with the corresponding group of source language statements (expanding). Normally, it performs no analysis of the text it handles. The design of a macro processor generally is machine independent.In this project,a macro processor which analyses the given macro lines into tokens of label,opcode,operand and stored seperately.It is processed to produce the expanded output.Our approach is to build a single pass macro processor.2.2 Basic concepts of Macro processorA macro processor is a program that reads a file (or files) and scans them for certain keywords. When a keyword is found, it is replaced by some text. The keyword/text combination is called a macro.

Assembler directives are used in macro definition are 1)MACRO: identify the beginning of a macro definition. 2)MEND: identify the end of a macro definition.

Prototype for the macroEach parameter begins with & name MACRO parameters:body:MEND

Basic Macro Processor Functions

Macro definition: It defines how to expand a single language statement or computer instruction into a number of instructions.Macro Expansion: A macro call leads to macro expansion. During macro expansion, the macro statement is replaced by sequence of assembly statements. Argumentsfrom the macro invocation are substituted for the parametersin the macro prototype (according to their positions).

2.3 Types of Macro ProcessorThere are two types of macroprocessor :-1) Two pass Macroprocessor.2) One pass Macroprocessor.2.3.1 Two pass Macro processorIn this type,1 pass macro definations are taken care and in 2 pass they are expanded to produce output But, it will not allow the body of one macro to contain definitions of other macros. Nested definition of macros is useful some time.Pass I Examine every operation code Save all macro definitions in a MDT( Macro Definition Table) Save a copy of the input text, minus macro definitions on secondary storage for use in pass II Prepare a Macro Name table(MNT) Pass II Examine every string in program Replace each macro name with the appropriate text from the macro definition.

2.3.2 One pass Macro processorone-pass macro processor that alternate between macro definitionand macro expansionin a recursive way is able to handle recursive macro definition.Restriction The definition of a macro must appear in the source program before any statements that invoke that macro.

Flowchart:

Fig 2.a flowchart of 1 pass macro processor Data Structure

DEFTAB (definition table)1) To Stores the macro definition includes prototype and macro body.2) Comment lines are omitted.3) References to the macro instruction parameters are converted to a positional notation for efficiency in substituting arguments.

NAMTAB1) Stores macro names.2) Serves as an index to DEFTABby pointing to the beginning and the end of the macro definition (DEFTAB)

ARGTAB(argument Table)1) Stores the arguments of macro invocation.2) As the macro is expanded, arguments from ARGTAB are substituted for the corresponding parameters in the macro body.

Chapter-3 Software Requirements Specification

2.1 Hardware and Software RequirementsThe hardware and software requirements for this project are limited to only the requirements of a C compiler on a UNIX or Windows machine.

Hardware Requirements 1. Pentium 60 MHz or higher.2. 256 MB RAM or higher. 3. 10 MB hard-disk space free (not including swap space required for the OS)

Software Requirements 1. DEV C++ IDE.2. Windows 98 or later.3. Implementable on UNIX OS with minor adjustments

2.2 Description of Tools used Dev C++ : Bloodshed Dev-C++is a full-featured Integrated Development Environment (IDE) for the C/C++ programming language. It usesMingwport ofGCC(GNU Compiler Collection) as its compiler. It creates native Win32 executables, either console or GUI. Dev-C++ can also be used in combination withCygwin.

Chapter-4 HIGH LEVEL DESIGN

Design ConstraintsThe design of macro processor doesnt depend on the architecture of the machine.We will be studying some extended feature for this macro processor. These features are: Concatenation of Macro Parameters Generation of unique labels Conditional Macro Expansion Keyword Macro Parameters

4.1 Concatenation of unique labels:Most macro processor allows parameters to be concatenated with other characterstrings. Suppose that a program contains a series of variables named by the symbolsXA1, XA2, XA3,, another series of variables named XB1, XB2, XB3,, etc. If similarprocessing is to be performed on each series of labels, the programmer might put this as amacro instruction. The parameter to such a macro instruction could specify the series ofvariables to be operated on (A, B, etc.). The macro processor would use this parameter toconstruct the symbols required in the macro expansion (XA1, Xb1, etc.).

4.2 Generation of Unique LabelsIt is not possible to use labels for the instructions in the macro definition, since every expansion of macro would include the label repeatedly which is not allowed by the assembler. This in turn forces us to use relative addressing in the jump instructions. Instead we can use the technique of generating unique labels for every macro invocation and expansion. During macro expansion each $ will be replaced with $XX, where xx is a two-character alphanumeric counter of the number of macro instructions expansion.

4.3 Conditional MacroConditional if and conditional while is used in macro expansion. This capability adds greatly to the power and flexibility of amacro language.Macro processor directives: IF-ELSE-ENDIF, WHILE-ENDW.The testing of Boolean expression in IF statements occurs at the time macros are expanded. By the time the program is assembled, all such decisions havebeen made. There is only one sequence of source statements during program execution.Macro time variableIt begins with &but is not a macro instruction parameter. Can be used to store working values during the macro expansion4.4 Keyword Macro ParametersAll the macro instruction definitions used positional parameters. Parameters and arguments are matched according to their positions in the macro prototype and the macro invocation statement. The programmer needs to be careful while specifying the arguments. If an argument is to be omitted the macro invocation statement must contain anull argument mentioned with two commas.Positional parameters are suitable for the macro invocation. But if the macro invocation has large number of parameters, and if only few of the values need to be used in a typical invocation, a different type of parameter specification is requiredKeyword parameters Each argument value is written with a keyword that names the corresponding parameter. Arguments may appear in any order. Null arguments no longer need to be used.It is easier to read and much less error-prone than the positional method.

4.5 LanguageC programming language is used.

4.6 Future plansMacro processor has main application in these areas:Language extension, Language translation, Text generation, Systematic editing.It can be used as a translator, Given a language A and a language B, together with some rules for translating from A to B, then an application for a macro processor might be to translate from A to B. Clearly this goal can only be realized in a limited number of cases. In particular, macros are not suitable for translating between natural languages, since this area requires very specialised techniques. However, taking A to be a high-level programming language and B to be the assembly language for some machine, then it might be possible for a macro processor to perform the compilation from A to B.

4.7 Data flow diagram

Level 0:

It is initial level of data flow diagram, scource code is taken as input and expanded code is produced which is passed as input to assembler.

Level 1 :

Here, source code is broken into tokens and passed into identify module.It checks whether the opcode is Macro or it is defined in the code.and passed to substitute module,where it expands or replaces macro as identified by previous module.

Level 2:

Source code is processed into word scanner,each word or a macro line is checked by processline.It searches NAMTAB for opcode,or MACRO opcode else expand it.Define enters defination and prototype into DEFTAB and NAMTAB respectively.GETLINE substitute actual arguments with formal parameters.and EXPAND produces expanded output.

Chapter-5 DETAILED DESIGN

This chapter discuss about the data structure and control flow in the software with much more details about software modules by clarifying the details about each function with functionality, purpose, input and output. The decision taken are based on certain design considerations, constraints and dependencies which will affect the subsequent functioning of the product.5.1 Data Structures for Macro processor

DEFTAB (definition table)1)To Stores the macro definition includes prototype and macro body.2)Comment lines are omitted.3) References to the macro instruction parameters are converted to a positional notation for efficiency in substituting arguments.

NAMTAB1) Stores macro names.2) Serves as an index to DEFTABby pointing to the beginning and the end of the macro definition (DEFTAB)

ARGTAB(argument Table)1) Stores the arguments of macro invocation.2) As the macro is expanded, arguments from ARGTAB are substituted for the corresponding parameters in the macro body.

5.2 Data Flow Diagram of an overall system

5.3 Description of each Module5.3.1 Word Scan:1. Functionality: This module is responsible to scan the macro line and process it.1. Input: source code with defination before main code.1. Output: Tokens produced are passed to processline .1. Flow Chart: The Flow Chart for the search module is shown in figure 0.1.11. Dependency: It depends on source code data.5.3.2 Process line:1. Functionality: Searches in the NAMTAB for opcode if found control is transferred to expand, else if opcode is Macro control is transferred to define,else the line is transferred to expanded code file.1. Input: Tokens.1. Output: control is transferred to define, expand, getline.1. Flow Chart: The Flow Chart for the search module is shown in figure 0.1.21. Dependency: It depends on word Scanner.Algorithm:procedure PROCESSLINEbegin search NAMTAB for OPCODEif found thenEXPAND else if OPCODE = MACRO thenDEFINEElse write source line to expanded fileEnd (PROCESSLINE)

5.3.3 Define:.1. Functionality: Enters the Macro name into NAMTAB and prototype into DEFTAB, comment lines are neglected. Care is taken if a Macro is called within a Macro. Hence prototype is stored in NAMTAB with beginning and end pointer 1. Input : Macro line which contain MACRO opcode.1. Output: completed DEFTAB and NAMTAB.1. Flow Chart: The Flow Chart for the search module is shown in figure 0.1.31. Dependency: It depends on processline , it checks opcode is MACRO and transfer control to define. Algorithm:procedure DEFINEbeginenter macro name into NAMTAB enter macro prototype into DEFTABLEVEL := 1While LEVEL > 0 doBeginGETLINEIf this not a comment line thenBeginsubstitute positional notation for parameters enter line into DEFTABif OPCODE = MACROLEVEL := LEVEL + 1else if OPCODE =: MEND thenLEVEL := LEVEL - 1 end (if not comment)end ( while )store in NAMTAB pointers to beginning and end of definition end (DEFINE)

5.3.4 Getline:1. Functionality: If Expanding is true, line is taken from DEFTAB and arguments are substituted for positional notation.1. Input: Macro line from DEFTABOutput: Argument Substituted code..1. Flow Chart: The Flow Chart for the search module is shown in figure 0.2.11. Dependency: It depends on define by taking macro line and substitute with arguments. Algorithm:procedure GETLINE begin if EXPANDING thenbeginget next line of macro definition from DEFTABsubstitute arguments from ARGTAB for positional notationend ( if )else read next line from input fileend {GETLINE}

5.3.5 Expand:

1. Functionality: Expanding is assigned true. Macro prototype is taken from DEFTAB and macro invocation arguments are copied to ARGTAB. Control is transferred to getline and processline until end of Macro definition. 1. Input: Argument Substituted code.1. Output: Expanded code.1. Flow Chart: The Flow Chart for the search module is shown in figure 0.2.21. Dependency: It depends on getline to get the actual argument substituted code.Algorithm:

procedure EXPANDbegin EXPAND := TRUE Get first line of macro definition (prototype) from DEFTABSet up arguments from macro invocation in ARGTAB Write macro invocation to expand file as comment While not end of macro definition dobegin GETLINE PROCESSLINE end ( while )EXPANDING := FALSEend ( expand )

DEFTAB:Description: It is used to Stores the macro definition includes prototype and macro body. Comment lines are omitted.References to the macro instruction parameters are converted to a positional notation for efficiency in substituting arguments.

NAMTAB:Description: Stores macro names, Serves as an index to DEFTAB by pointing to the beginning and the end of the macro definition (DEFTAB)

ARGTAB:Description:Stores the arguments of macro invocation. As the macro is expanded, arguments from ARGTAB are substituted for the corresponding parameters in the macro body.Expanded code:Description:Data stored after processed by macro processor. The code is brought to the state to be processed by compiler or assembler.

Chapter-6 IMPLEMENTATION

6.1 AlgorithmThe following functionalities are implemented in our C code for macro processor:

MACROPROCESSOR

EXPANDING=FALSE. Read each line and call GETLINE() and PROCESSLINE() until END encounters.

PROCESSLINE ( )

If OPCODE is a macroname then EXPAND ( ). Else if OPCODE is MACRO ,then DEFINE ( ). Else write line to expanded file as such.

DEFINE( )

Enter Macro name into NMATAB. Enter macro prototype into DEFTAB. Set LEVEL=1. Substitute parameters with positional notations and enter to DEFTAB. If OPCODE=MACRO, LEVEL++; If OPCODE=MEND, LEVEL--; Continue this until LEVEL=0 Store beginning and end of definition as pointers within NAMTAB

EXPAND ( )

EXPANDING = TRUE Set up arguments from macro invocation in ARGTAB. Write macro invocation statement to expanded file as a comment line. Call GETLINE() and PROCESSLINE() till macro definition ends. Set EXPANDING=FALSE.

GETLINE ( )

If EXPANDING is TRUE, read from DEFTAB (data structure where macro body is stored) and substitute arguments for positional notations. If EXPANDING is FALSE , read next line from input file.

UINQUE LABEL GENERATION

a. Labels in the macro body may cause duplicate labels problem if the macro is invocated and expanded multiple times.b. Use of relative addressing at the source statement level is very inconvenient, errorprone, and difficult to read.c. It is highly desirable to- let the programmer use label in the macro bodya. Labels used within the macro body begin with $.- let the macro processor generate unique labels for each macro invocation and expansion.b. During macro expansion, the $ will be replaced with $xx, where xx is a twocharacter alphanumeric counter of the number of macro instructions expanded.c. XX=AA, AB, AC,.

6.2 Language used in implementation

C programming language is used because:

Modularity: modularity is one of the important characteristics of C. we can split the C program into no. of modules instead of repeating the same logic statements (sequentially). It allows reusability of modules.

Middle level language: as a middl e level language C combines both the advantages of low leve l and high leve l languag es. (arrays,pointers etc).

General purpose programming language: C can be used to implement any kind of applications such as math s oriented, graphics, business oriented applications.

Portability: we can compile or execute C pro gram in any operating system (unix,dos,windows).

Powerful programming language: C is very efficient and powerful programming language, it is best use d for data structures and designing system software.

C is case sensitive language.

6.3 Error DetectionThe C programming language providesperror()andstrerror()functions which can be used to display the text message associated witherrno.

Chapter-7 SOFTWARE TESTING

At testing stage of this project, defects or errors were discovered by testing individual program components. Testing was focused on establishing functional requirements and on system behavior in given scenario. The test cases are selected to ensure that the system behavior can be examined in all possible combinations of conditions. Accordingly, expected behavior of the system under different conditions is given. Therefore test cases are selected which have inputs and the outputs are as expected.

7.1 Testing ProcessTesting is an integral part of software development. Testing process, in a way certifies, whether the product, that is developed, complies with the standards, that it was designed to. Testing process involves building of test cases, against which the product has to be tested. In some cases, one drives the test cases from the requirements of the product/software, which is to be developed.

7.2 Levels of Testing Different levels of testing are used in the testing process, each level of testing aims to test different aspects of the system. The basic levels are unit testing, integration testing, system testing and acceptance testing.

7.3 Unit Testing The first level of testing is called unit testing. Unit testing focuses verification effort on the smallest unit of software design module.In this different modules are tested against the specifications produced during design for the modules. Unit testing is essentially for verification of the code produces during the coding phase, and hence the goal is to test the internal logic of the modules. It is typically done by the parameter of the module. Due to its close association with coding, the coding phase is frequently called coding and unit testing .The unit test can be conducted in parallel for multiple modules.

7.4 Integration Testing The second level of testing is called integration testing. Integration testing deals with finding defects in the way individual parts work together. In this, many unit tested modules are combined into subsystems, which are then tested. The goal here is to see if all the modules can be integrated properly.

7.5 System Testing and Acceptance Testing Here the entire software system is tested. The reference document for this process is the requirements document and the goal is to see if the software meets its requirements. Acceptance testing is sometimes performed with realistic data to demonstrate that the software is working satisfactorily. Testing here focuses on the external behavior of the system.

7.6 Unit Testing of Main ModulesUnit testing is the process of testing individual components in the system. This is a defect testing process so its goal is to expose faults in these components. Individual functions or methods are the sample type of component and tests are the set of calls to these routines with different parameters. Here different modules are tested independently and their functionality and usability is checked. There are 3 test cases for dictionary creation is tested as shown below Table7.1 to Table 7.3.Table 7.1 Expansion of MacroTest case 1

Sl. No. of test case :1

Name of test :Macro expansion

Item / Feature being tested :Macro

Sample Input :Program with macros

Expected output :Program with macros expanded.

Actual output :Program with macros expanded.

Remarks :Test succeeded

Test case 1 as shown in table 7.1 tests the expansion of the macro in the given input file. After successfully expanding , the program with expanded macros is given as output.

Table 7.2 Generation of unique labels test case 2

Sl. No. of test case :2

Name of test :Generation of unique labels

Item / Feature being tested :Unique labels

Sample Input :Macro program with labels

Expected output :Program with unique labels generated.

Actual output :Program with unique labels generated.

Remarks :Test succeeded.

Test case 2 as shown in table 7.2 searches the labels in the program. And finally it generates the unique labels in the out file

Table 7.3 nested macro unit test case 3

Sl. No. of test case :3

Name of test :Nested macro

Item / Feature being tested :Nested macro

Sample Input :Program with nested macros.

Expected output :Program with nested macros expanded.

Actual output :Program with nested macros expanded.

Remarks :Test successful.

Test case 3 as shown in table 7.3 tests the nested macros in the program and expands them accordingly and the output program with macros expanded is obtained.

Table 7.4 Time to expand a macro unit test case 4

Sl. No. of test case :4

Name of test :Time to expand a macro in program

Item / Feature being tested :Macro processor

Sample Input :Program with macro

Expected output :Program with macro, is expanded in 0.019 seconds.

Actual output :Program with macro, is expanded in 0.019 seconds.

Remarks :Test successful.

Test case 4 as shown in table 7.4 checks the total time required to expand the macro by macro processor.Timer is started, before expanding the macro starts and timer is stopped after the macro processor has expanded. The duration is calculated and displayed as output on the screen. Sample output test is shown in above table. 7.7 SummaryImplementation describes the important decisions taken for the development of the project. Programming language selection which can help in the designing of the project efficiently is chosen. The platform selection is described based on the requirement of the project. The coding convention used in the project is explained in detail. Software testing deals with the testing of each module to meet the functional requirements. Various stages of testing are included. The test cases to test and their respective outcomes are tabulated.

CHAPTER 8RESULTS, DISCUSSION AND INFERENCE

8.1 Advantages and DisadvantagesThe following are the major advantages of the project Effectively replaces code that was meant for replacement with the macro. Used concepts such as file pointers, structures to carry out its tasks Highlights errors caused by macros that the programmer can rectify before the code is sent for compilation rather than to be intimated of errors during compilation Produces the output file, even if there are errors or warnings in the input file. Maintains a separate input file and a separate output file for data verification and rectification. Maintains macro names and their definitions in structures, thereby reducing the amount of resources involved with character arrays and is useful for debugging purposes. Tabs and whitespaces and original contents of the input file are maintained as they are even in the final source code file.

The following are the major disadvantages of the project Conditional macros are not taken care only simple macros, parameterized macro, macro within macros are taken care off. The input file has to be prepared as a text file, which means the programmer will have to first save his program as a .txt file. Also, the output file is created as a .txt file, which means the programmer will have to bring this output file back to the IDE for compilation. Compilation errors would require the programmer to start the process from scratch

8.2 Future Enhancements

Based on the development of the project, there is sufficient scope for further enhancement. Enhancements can be made by way of improving on existing features, addition of new features, removal of constraints and increasing flexibility to macros. Some of the possible future enhancements are as follows:

Taking care of conditional macros Conditional macros like the if, elseif, while,endwhile else are not taken into account by using macro time variable to store value during execution of conditions.

Inclusion of a compiler Steps can be taken to develop an IDE (Integrated Development Environment), so that the output cpp file can be directly compiled and the results caused due to macro expansions can be taken care of. However, the development of an IDE would require also the development of an editor, a parser, linker and other systems software concepts that are well beyond the boundaries of a simple macro processor. However, with the combination of a compiler, the use of macros can be fully justified.

User-defined macros

User-defined macros can be setup to help programmers work with arrays and filesbetter. These macros can be used to perform regular tasks such as arranging elements in ascending or descending order, or to open files with a given filename and file mode. These specifics can be applied with more input from the programmer as to how he would like to lessen the amount of typing and to help increase readability.

REFERENCES

1) ANDREW S. TANENBAUM, A General-Purpose Macro Processor as a Poor Man's Compiler-Compiler, IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. SE-2, NO. 2, JUNE 1976

2) P. J. Brown, "The ML/I macro processor," Commun. Ass. Comput. Mach., vol. 10, pp. 618-623, Oct. 1967.

3) W. Wulf, D. Russell, and A. Habermann, "BLISS: A language for systems programming," Commun. Ass. Comput. Mach., vol.14, pp. 780-790, Dec. 1971.

4) P. J. Brown, "Macro processors and software implementation," Comput. J., vol. 12, pp. 327-331, Nov. 1969.

5) Marshall, Martin (April 29, 1991)."Macro Assembler Update Adds High-Level Features".InfoWorld13(17): p. 21.ISSN0199-6649.

Appendices Appendix A

Source code

Code.c

#include#include#include.#include str_rep.h FILE *input_f,*output_f;int main (){ int test; int counter=99; int j,check_endof_macro; check_endof_macro=1; j=0; input_f = fopen("input.txt","r"); output_f = fopen("expanded.txt","w"); while(1){ j++; if( feof(input_f) ){break ; } fscanf(input_f,"%s %s %s",label,opcode,operand); counter=search(opcode); if(counter!=99) {

write_to_file(1,counter); printf("\nok\n");continue; //Not to read same line again } write_to_file(0,0); if(strcmp(opcode,"MACRO")==0){ strcat(arg[c_d], operand); strcat(name[c_d], label);check_endof_macro=1; while(check_endof_macro) { fscanf(input_f,"%s %s %s",label,opcode,operand); counter=search(opcode);if(counter!=99){nestmacro(counter,c_d); printf("\nok\n");continue; } write_to_file(0,0); check_endof_macro=strcmp(opcode,"MEND"); if(check_endof_macro!=0) {

write_to_deftab(c_d); } } c_d++; } }test=search("RBUFF");

fclose(input_f);}

int countdef=0; int c,expnd=0; char label[20],opcode[20],operand[20]; char name[10][10]={"","","","","","","","","",""},arg[10][100]={"","","","","","","","","",""},def[30][4096]={"","","","","","","","","",""};char unique_Label='A';

int search(char *macro_name){int i;

for(i=0;i0) { pch = strtok (str,","); while (pch != NULL && count_Split>1) { pch = strtok (NULL, ","); count_Split--; } } //printf("%s\n",pch ); return pch;

}/*int count_Argtab(char a[30]){int count_arg=0,i=0;/*char *t;t=st;//*s='\0';printf("%s\n",t);while(*t!='a'){if(*t==',')count_arg++;printf("check\n");t++;}*//*printf("%s\n",a );int len=strlen(a)-1;printf("%c\n",a[0] );while(i!=3){if(!strcmp(',',a[i]))count_arg++;i++;}return count_arg;}*/

int write_to_file(check_Expand,counter){char operands[10][128]={"","","","","","","","","",""};char arg_operands[10][128]={"","","","","","","","","",""};char * pch;char *split_opnd=" ";char *token;int icount=0,len=0,ii=0,count_arg=0,i,count_Split;char *opnd_Replace;char dummy[128]={""};char def_buffer[4096];if(check_Expand==1){fprintf(output_f, ";");fprintf(output_f, label);fprintf(output_f, " ");fprintf(output_f, opcode);fprintf(output_f, " ");fprintf(output_f, operand);fprintf(output_f, "\n");//printf("%s",split_Argtab(arg[counter],2));//Splitting Operandlen=strlen(operand)-1;while(ii!=len){if(operand[ii]==',')count_arg++;ii++;}/*for ( i = 0; i 0) { split_opnd = strtok (operand,","); while (split_opnd != NULL && count_Split>1) { split_opnd = strtok (NULL, ","); count_Split--; } }; strcat(operands[i],split_opnd);}*/ for (i =0; i