Presentation is loading. Please wait.

Presentation is loading. Please wait.

COP 3402 Systems Programming

Similar presentations


Presentation on theme: "COP 3402 Systems Programming"— Presentation transcript:

1 COP 3402 Systems Programming
Dr. Ali Orooji School of EECS University of Central Florida

2 Chapter 4 - MACRO PROCESSORS
Function macro expansion; substitute macro bodies for macro invocations Source Program with macro invocations Macro procesor Source Program with macros expanded assembler

3 Two-Pass Macro Processor
process macro definitions Pass 2 expand macro invocations Problem would not allow the body of one macro to contain definitions of other macros

4 PMAC MACRO ... C1MAC MACRO ... ... MEND C2MAC MACRO ...

5 One-Pass Macro Processor
. will process macro definitions and expand macro invocations at the same time; will alternate between macro definition and macro expansion . the definition of a macro must come before any of its invocations Macro Processor Data Structures definition table DEFTAB DEFTBL - macro definitions are stored in this table - references to parameters are converted to a positional notation for efficiency in substituting arguments

6 name table NAMTAB NAMTBL
- macro names are stored in this table along with pointers to the beginning and end of definitions in DEFTAB; serves as an index to DEFTAB argument table ARGTAB ARGTBL - used during the expansion of macro invocations - arguments in a macro invocation are stored in this table Macro Processor Logic pages of text Figure 4.5 Algorithm for a one-pass macro processor

7 Machine-Independent Macro Processor Features
Section 4.2 Machine-Independent Macro Processor Features Generation of Unique Labels MAC MACRO ... LBL MEND first macro expansion AALBL second macro expansion ABLBL

8 Conditional Macro Expansion
IF ( Boolean expression ) ... ELSE ENDIF WHILE ( Boolean expression ) ENDW

9 Macro Processor Design Options
Section 4.3 Macro Processor Design Options Recursive Macro Expansion Problems with previous macro processor - when a macro invokes another macro ARGTAB is overwritten - when the second macro finishes EXPANDING is set to FALSE

10 Solution - if macro processor is written in a high-level
language that supports recursion, then there won't be problems since the compiler saves the previous values of variables on recursive calls - if macro processor must be written in a programming language that does not support recursion, then the system programmer must save the data values (this can be done using a stack)

11 General-Purpose Macro Processors
not dependent on any particular programming language; can be used with a variety of different languages Problems - problems related to different programming languages . comments . facilities for grouping . tokens (identifiers, operators, ...) - syntax used for macro definitions and macro invocations

12 Macro Processing within Language Translators
previous macro processor: pre-processor alternative: combining the macro processing functions with the language translator . line-by-line macro processor . integrated macro processor


Download ppt "COP 3402 Systems Programming"

Similar presentations


Ads by Google