Macro Processor Design Options Recursive Macro Expansion General-Purpose Macro Processors Macro Processing within Language Translators.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

COP 3402 Systems Programming
Infix, Postfix and Stacks
The Assembly Language Level
Macro Processor.
Macro Processors (MP) Macro: Macro Processors (MP): Examples:
8.2 Characteristics of a High Level Programming Language
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
An introduction to systems programming
1 Chapter 4 Macro Processors Source Code (with macro) Macro Processor Expanded Code Compiler or Assembler obj.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Chapter 4 Macro Processors
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function.
1 Chapter 4 Macro Processors Professor Gwan-Hwan Hwang Dept. Computer Science and Information Engineering National Taiwan Normal University 9/17/2009.
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
A Simple Two-Pass Assembler
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
Lexical Analysis Hira Waseem Lecture
Chapter 1 Computer architecture Languages: machine, assembly, high
An introduction to systems programming
Machine Independent Macro Processor Features Concatenation of Macro Parameters Generation of Unique Labels Conditional Macro Expansion Keyword Macro.
4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II.
Objective At the conclusion of this chapter you will be able to:
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 7 – Subroutines These are lecture notes to accompany the book SPARC Architecture,
ICS312 Set 14 MACROS. Macros The program structure is similar to that for procedures. As for procedure names, macro names represent a group of instructions.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 11: Functions and stack frames.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Introduction to Language Programming Hierarchy of programming lang. Based on machine independences: 1. Machine language 2. Assembly language 3. Higher.
Macro Processors Basic Functions Machine-Independent Features Design Options Implementation Examples.
 A macro represents a commonly used group of statements in the source programming language.  The macro processor replaces each macro instruction with.
Functions Skill Area 314 Part B. Lecture Overview Functions Function Prototypes Function Definitions Local Variables Global Variables Default Parameters.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
1 Chapter 4 Macro Processors. 2 Introduction A macro instruction (abbreviated to macro) is simply a notational convenience for the programmer. A macro.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 11–Macro-Processors.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Definition of the Programming Language CPRL
CS 3304 Comparative Languages
Machine Independent Assembler Features
F453 Computing Questions and Answers
FUNCTIONS In C++.
C Language VIVA Questions with Answers
Choice of Programming Language
Data Structures Recursion CIS265/506: Chapter 06 - Recursion.
MACRO Processors CSCI/CMPE 3334 David Egle.
Chapter 4 Macro Processors
Application Binary Interface (ABI)
CSCE Fall 2013 Prof. Jennifer L. Welch.
CSC 533: Programming Languages Spring 2015
C Preprocessor(CPP).
Algorithm for One-pass Macro Processor
by Richard P. Paul, 2nd edition, 2000.
A Simple Two-Pass Assembler
CSCE Fall 2012 Prof. Jennifer L. Welch.
Chapter 1 Computer architecture Languages: machine, assembly, high
Chapter 6 Programming the basic computer
UNIT – IV MACRO PROCESSORS
CSC 533: Programming Languages Spring 2018
CSC 533: Programming Languages Spring 2019
CHAP 4 MACRO PROCESSORS.
Presentation transcript:

Macro Processor Design Options Recursive Macro Expansion General-Purpose Macro Processors Macro Processing within Language Translators

Recursive Macro Expansion

Recursive Macro Expansion RDCHAR: read one character from a specified device into register A should be defined beforehand (i.e., before RDBUFF)

Implementation of Recursive Macro Expansion Previous macro processor design cannot handle such kind of recursive macro invocation and expansion, e.g., RDBUFF BUFFER, LENGTH, F1 Reasons: The procedure EXPAND would be called recursively, thus the invocation arguments in the ARGTAB will be overwritten. The Boolean variable EXPANDING would be set to FALSE when the “inner” macro expansion is finished, that is, the macro process would forget that it had been in the middle of expanding an “outer” macro. A similar problem would occur with PROCESSLINE since this procedure too would be called recursively. Solutions: Write the macro processor in a programming language that allows recursive calls, thus local variables will be retained. Use a stack to take care of pushing and popping local variables and return addresses. Another problem: can a macro invoke itself recursively?

General-Purpose Macro Processors Goal: macro processors that do not dependent on any particular programming language, but can be used with a variety of different languages Pros Programmers do not need to learn many macro languages. Although its development costs are somewhat greater than those for a language-specific macro processor, this expense does not need to be repeated for each language, thus save substantial overall cost. Cons Large number of details must be dealt with in a real programming language Situations in which normal macro parameter substitution should not occur, e.g., comments. Facilities for grouping together terms, expressions, or statements Tokens, e.g., identifiers, constants, operators, keywords Syntax

Macro Processing within Language Translators Macro processors can be Preprocessors Process macro definitions Expand macro invocations Produce an expanded version of the source program, which is then used as input to an assembler or compiler Line-by-line macro processor used as a sort of input routine for the assembler or compiler Read source program Process macro definitions and expand macro invocations Pass output lines to the assembler or compiler Integrated macro processor

Line-by-Line Macro Processor Benefits It avoids making an extra pass over the source program. Data structures required by the macro processor and the language translator can be combined (e.g., OPTAB and NAMTAB) Utility subroutines can be used by both macro processor and the language translator. Scanning input lines Searching tables Data format conversion It is easier to give diagnostic messages related to the source statements.

Integrated Macro Processor An integrated macro processor can potentially make use of any information about the source program that is extracted by the language translator. As an example in FORTRAN DO 100 I = 1,20 a DO statement: DO: keyword 100: statement number I: variable name DO 100 I = 1 An assignment statement DO100I: variable (blanks are not significant in FORTRAN) An integrated macro processor can support macro instructions that depend upon the context in which they occur.

Drawbacks of Line-by-line or Integrated Macro Processor They must be specially designed and written to work with a particular implementation of an assembler or compiler. The costs of macro processor development is added to the costs of the language translator, which results in a more expensive software. The assembler or compiler will be considerably larger and more complex.