// Tab Setting = 4
 Ŀ
                               Macro Processor                             
 


			   Software Laboratory - II ( System Programming )
			 


								X - Macro Processor
								

				  Ŀ
				       1. Problem Definition        
				       2. Program Specifications    
				       3. Assumptions               
				       4. Data structures           
				       5. Algorithm                 
                       6. Future Expansion          
				  


 1. Problem Definition :
	


		Design a Macro Processor for hypothetical assembly language.


 2. Program Specifications :
	


		X - Macro Processor is a Single pass macro processor.

			  *		Input  : .asm source code file with or without
					-	 Macro definitions and macro calls

			  *		Output : .asm file with no macro definitions and
					-	 macro calls

 3. Assumptions     :
    
   

   While designing the macro processor few assumptions regarding the structure
   of macro definitions and macro calls have been made.They are as follows.

		<a>. Macro definitions must be written before actual call.
		<b>. Macro definitions must preceed data and code segment.
		<c>. No nested definitions are allowed.
		<d>. Nested macro calls are allowed.
		<e>. Ideally no limit on depth of nesting of macro calls.
        <f>. No recursive macro calls are allowed.
        <g>. Macro definition must begin with keyword 'macro'.
        <h>. Macro definition must end with keyword 'endm'.
        <i>. Whenever you want to call a macro,put symbol '^' before actual
             macro name.
        <j>. Default parameters are allowed.
        <k>. All default parameters (if present) must start from left of
             parameter list.
        <l>. Whenever you want to use dafault parameter, put symbol '_' at
             corresponding parameter position.
         

 4. Data Structures :
	
            <1>. Macro Definition Table (MDT) :-
                 

                 The data structure used for MDT is simple two dimensional
                 array.

                 MDT pointers :

                 NEXT_FREE_MDT_POS : This pointer points at the next free
                                     location in the MDT.
                 CUR_MDT_POS       : This pointer points at the current
                                     instruction in MDT.

            <2>. Macro Name Table (MNT) :-
                 

                 The data structure used for MNT is Array of structures.
                 The structure holds all the required information regarding
                 macro like Start and End positions of macro definition in
                 the MDT , pointer to the Formal v/s positional parameter
                 list etc.

                 MNT pointers :

                 NEXT_FREE_MNT_POS : This pointer points at the next free
                                     location in the MNT.
                 CUR_MNT_POS       : This pointer points at the current
                                     macro in MNT.


            <3>. Stack :
                 

                 Stack is implemented using array.

                 Stack is used while processing Nested Macro Calls.

                 Each stack element is a structure which holds the minimum
                 environment for parent macro when child macro is to be
                 expanded.

            <4>. Label Table :-
                 

                 Label table is an array of structures.

                 Each label encountered is put in the Label Table along
                 with its usage counter.

                 Usage counter is used to generate new labels to aoid
                 duplication of labels.

                 NEXT_FREE_LABEL_TABLE_POS : This pointer points at the next
                           free location in Label Table.

            <5>. Formal v/s Positional parameters list
                 
                 Positional v/s Actual parameters list  :-
                 


                 The data structure LINKED LIST is used to store the
                 parameters.

                 CUR_FP_PP_LIST : This pointer points at the Formal v/s
                                  positional parameter list of current macro.

                 CUR_PP_AP_LIST : This pointer points at the Positional v/s
                                  actual parameter list of current macro.
            
            

 5. Algorithm :
	


            1.  Read a single line from the input asm file.
            2.  Separate out the tokens.
            3.  Now there are 4 cases to be considered,according to which
                DEFINITION and EXPANSION flags will set or reset.
            4.  Depending upon the FLAGS status perform any one of the
                following actions.

   MACRO_EXPANSION     MACRO_DEFINITION        READ_FROM        WRITE_INTO

     0                    0                    INPUT .ASM        BUFFER
     0                    1                    INPUT .ASM         MDT
     1                    0                        MDT           BUFFER
     1                    1                        MDT            MDT

            6. if Not End of File
                GoTo step 1
               else
                {
                   check if errors are present or not
                   if (no errors present)
                     write final asm file ( which is free of macro definitons
                                            and macro calls )
                }
        


 6. Future Expansion :-
    

             Macro design can be made more complicated by adding following
             things to current design.

             1. Keyword parameters
             2. Overloading of macros
             3. Definition within definition



                              
							  End of readme.txt
                              
                              
