Algorithm for One-pass Macro Processor

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

COP 3402 Systems Programming
By Senem Kumova Metin 1 DATA TYPES. by Senem Kumova Metin 2 DATA TYPE? …… x; // DECLARATION OF VARIABLE X printf(“Do you want to go on? \n”) printf(“Please.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Macro simple idea of textual substitution useful when you need a group of instructions or directives frequently.
Do I need a robot today? You only need a robot if your team has not shown me your octagon and/or the octagon in a function.
The Assembly Language Level
Macro Processor.
Macro Processors (MP) Macro: Macro Processors (MP): Examples:
1 Macro Processors. 2 Macro Processor l Recognize macro definitions l Save the macro definition l Recognize macro calls l Expand macro calls Source Code.
8.2 Characteristics of a High Level Programming Language
Chapter 14: Overloading and Templates C++ Programming: Program Design Including Data Structures, Fifth Edition.
An introduction to systems programming
1 Chapter 4 Macro Processors Source Code (with macro) Macro Processor Expanded Code Compiler or Assembler obj.
Chapter 4 Macro Processors
Chapter 15: Operator Overloading
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
1 Chapter 4 Macro Processors Professor Gwan-Hwan Hwang Dept. Computer Science and Information Engineering National Taiwan Normal University 9/17/2009.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
CH07: Writing the Programs Does not teach you how to program, but point out some software engineering practices that you should should keep in mind as.
CSCI 130 Scope of Variables Chapter 6. What is scope Parts of program which can access a variable –accessibility –visibility How long variable takes up.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
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.
PART I SISTEM UTILITIES LECTURE 5 MACROPROCESSING Ştefan Stăncescu 1.
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II.
Objective At the conclusion of this chapter you will be able to:
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Chapter 7 Functions. Types of Functions Value returning Functions that return a value through the use of a return statement They allow statements such.
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.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
Using Oracle-Supplied Packages. 2 home back first prev next last What Will I Learn? Describe two common uses for the DBMS_OUTPUT server-supplied package.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions Lecture 12.
CSCI 171 Presentation 6 Functions and Variable Scope.
Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.
(3-1) Functions II H&K Chapter 3 Instructor - Andrew S. O’Fallon CptS 121 (September 9, 2015) Washington State University.
Macro Processors.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
Lecture 15: Course Review BJ Furman ME 30 16MAY2011.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
1 CSC103: Introduction to Computer and Programming Lecture No 16.
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, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
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.
Macro Processor Design Options Recursive Macro Expansion General-Purpose Macro Processors Macro Processing within Language Translators.
Lecture 3 Translation.
Chapter 6 Modular Programming Dr. J.-Y. Pan Dept. Comm. Eng.
Variables A piece of memory set aside to store data
Assembler Design Options
2011/11/20: Lecture 15 CMSC 104, Section 4 Richard Chang
Using local variable without initialization is an error.
MACRO Processors CSCI/CMPE 3334 David Egle.
Chapter 4 Macro Processors
Structured Program Design
Register Variables Declaring a variable as a "register" variable is an advisory to the compiler to keep the normal location of the variable in a register,
Exam 4 review Copyright © 2008 W. W. Norton & Company.
Defining and Calling a Macro
الفصل الثاني الخوارزمية
Function Notation “f of x” Input = x Output = f(x) = y.
Fundamental Programming
Chapter 1 Computer architecture Languages: machine, assembly, high
UNIT – IV MACRO PROCESSORS
CHAP 4 MACRO PROCESSORS.
Preprocessor Directives and Macros Chapter 21
Presentation transcript:

Algorithm for One-pass Macro Processor main () /* main program */ { EXPANDING = 0; /* definition case; a control variable for reading input record from input sources */ while (OPCODE != ‘END’) { GETLINE (line); /* get a next line (from expansion or definition); label, opcode, operands */ PROCESSLINE (line); /* define or expand a line after getting it; label, opcode, operands*/ } PROCESSLINE (line) search NAMTAB for line.opcode; if (found) EXPAND (line); /* expand macro definition with arguments from invocation */ else if DEFINE (line); /* put macro definition in DEFTAB */ else write the source line to expand file; CmpE 220 - Software Systems Prof. Weider Yu

Algorithm for One-pass Macro Processor DEFINE (line) { enter line.label into NAMTAB; /* enter macro name into NAMTAB */ enter macro prototype into DEFTAB; /* the first declaration statement */ LEVEL = 1; while (LEVEL > 0) { GETLINE (line); /* get the next line of the macro definition */ if (line != comment line) { substitute positional notation for parameters; /* &param_1  ?1, etc. */ enter line into DEFTAB; if (OPCODE = ‘MACRO’) LEVEL = LEVEL +1; else if (OPCODE = ‘MEND’) LEVEL = LEVEL –1; } store pointers (label->begin and label->end) in NAMTAB; /* store macro def. begin and end pointers */ CmpE 220 - Software Systems Prof. Weider Yu

Algorithm for One-pass Macro Processor EXPAND (line) { EXPANDING = 1; /* expansion case; ready to read input from DEFTAB*/ get the first line of macro definition (macro prototype) from DEFTAB; set up arguments (from macro invocation) in ARGTAB; write macro invocation to expanded file (output file) as a comment; while (OPCODE != MEND) { /* while not end of macro definition */ GETLINE (line); PROCESSLINE (line); } EXPANDING = 0; /* macro expansion is done */ GETLINE (line) if (EXPANDING = 1) { get next line of macro definition from DEFTAB; substitute arguments from ARGTAB for position notation; else read next line from input file; /* read the source program file */ CmpE 220 - Software Systems Prof. Weider Yu

One-pass Macro Processor Algorithm A flow chart for the one-pass macro processor algorithm. 2 INPUT FILE READ (next line) 2 1 GETLINE READ (next line) MACRO PROCESSOR DEFTAB 5 SUBSTITUTE (arguments) 4 PROCESSLINE DEFINE ENTER (macro prototype/line) WRITE (source line) 3 5 EXPANDED FILE SEARCH 5 EXPAND ARGTAB NAMTAB ENTER (macro name) SET UP (arguments) CmpE 220 - Software Systems Prof. Weider Yu