M4 Macro-processing Language Geoffrey Sewell. What will be shown? What’s a macro processor? History of M4 Uses Autotools Syntax Hopefully, you all learn.

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

Macro simple idea of textual substitution useful when you need a group of instructions or directives frequently.
Macro Processor.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
1 Chapter 4 Macro Processors Professor Gwan-Hwan Hwang Dept. Computer Science and Information Engineering National Taiwan Normal University 9/17/2009.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
CSE341: Programming Languages Lecture 15 Macros Dan Grossman Spring 2013.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 19 - The Preprocessor Outline 19.1 Introduction 19.2 The #include Preprocessor Directive 19.3.
Introduction to Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Universal Linear Algebra API based on M4 Michael Fiero Isaac Asiamah.
Introduction to Shell Script Programming
An Introduction to Unix Shell Scripting
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Programming With C.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Input, Output, and Processing
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Profs. Necula CS 164 Lecture Top-Down Parsing ICOM 4036 Lecture 5.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 11: Shell.
An introduction to systems programming
Oracle Data Integrator Procedures, Advanced Workflows.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
XP Tutorial 8 Adding Interactivity with ActionScript.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Top-Down Parsing.
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
1 Lecture 10 Introduction to AWK COP 3344 Introduction to UNIX.
Macro Processors Basic Functions Machine-Independent Features Design Options Implementation Examples.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
The Scripting Programming Language
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
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.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Macro Processor Design Options Recursive Macro Expansion General-Purpose Macro Processors Macro Processing within Language Translators.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
CSE341: Programming Languages Lecture 15 Macros
Shell Scripting March 1st, 2004 Class Meeting 7.
Lecture 9 Shell Programming – Command substitution
Getting Started with C.
CSE341: Programming Languages Lecture 15 Macros
Introduction to C++ Programming
Coding Concepts (Basics)
CSE341: Programming Languages Lecture 15 Macros
CSE 303 Concepts and Tools for Software Development
CSE341: Programming Languages Lecture 15 Macros
CSE341: Programming Languages Lecture 15 Macros
The C Language: Intro.
CSE341: Programming Languages Lecture 15 Macros
CSE341: Programming Languages Lecture 15 Macros
Presentation transcript:

M4 Macro-processing Language Geoffrey Sewell

What will be shown? What’s a macro processor? History of M4 Uses Autotools Syntax Hopefully, you all learn something from this!!!

What’s a Macro- processor?

General Macro Processor Copies a stream of text to a different location Makes use of replacements GPM (General Purpose Macro processor)

Uses Language Expansion Textual Replacements Text Reformatting

History of M4 Developed in 1977 based off of ideas by Christopher Strachey Developed by Brian Kernighan and Dennis Ritchie Derives from GPM (the General Purpose Macroprocessor) Original macro used to run Rational Fortran –Provides a control structure for Fortran –Fortran is more like C

Uses of M4 Autotools Handle hierarchical files –M4 can recursively look through files Features –Arguments –Condition testing –Arithmetic –String and substring substitution –Macro Expansion

Autotools Collection of packages Tools to create build system from simple instructions Central place to put fixes and improvements

Tools Aclocal Autoheader Libtoolize Automake (explained later) Autoconf (explained later) Configure Libtool

AutoConf Automatically configures source code packages Able to allow packages to work with many kinds of UNIX systems Transform a user written configure.ac/.in file to a shell script Generates Configure file

AutoMake Produces makefiles for use with the make command Used with AutoConf Constructs Makefile.in, install-sh, missing, COPYING, depcomp

Why/ Why not use Autotools Why –Unpredictable Environment Why not –When it’s more troublesome to do it

Basic Constructs of M4

Name Sequence of characters (letters, numbers, ‘_’) that are binded to a macro Must not start with a number First01 alpha

Quotes String to be quoted is placed in ` and ‘ Must be balanced Can use quotes in the middle of another set of quotes –Expansions won’t occur if name is in quotes Changequote Nested quotes = stop expansion ``time’’ = `time’

Comments & Tokens Comments –Started by ‘#’ and ended by ‘\n’ (newlines) –Not ignored by the language –When ‘\n’ entered, comment is ended Tokens –Anything that’s not a name or a quote

Macro Invocation name1 Geof(arg1,arg2,arg3,…) Not a standard Macro Invocation –Bad() Empty Parentheses = empty string

Macro Invocation (cont.) Too few arguments… –Other arguments seen as an empty string –No error returned Arguments expanded first

Define New Macros Use define keyword Will map a name to an expansion –Expansion can involve another expansion Define(hey, `Hello World.’)

Delete Macro Undefine(`macroName’) `’ are necessary for this to be done Will unbind a macro name with an expansion

Macro Arguments Argument n refered to as $n Arguments are positional Define(switch, `$2, $1’) What’s the result?

Macro Defn Test Ifdef(name, string1, string2) Test to see if a Macro is defined Specialized if statement String 2 is optional

String Comparison ifelse Ifelse(string1, string2, equal, not-equal) Same concept as If Else statements in most programming languages Any Idea what this would do? Ifelse(cold, hot, `fresh’, clean, froggy, `tight’, `supafly’)

Special Characters $# - number of arguments $* - runs through all arguments $ - nothing special - same as $* but quotes argument

Rename Macros Defn(name) Copy a macro expansion to another name Only works if it’s considered to be an expansion

Counting and Arithmetic Incr(#) Decr(#) Eval(expr) where expression is an arithmetic expression

Redefine Like a stack Can have multiple definitions for a macro Pushdef(name, expansion) –Add expansion to macro Popdef(name) –Takes away an expansion associated with a macro Define will replace top most expansion

Recursion Works like most other languages define(`reverse', `ifelse($#, 0,, $#, 1, "$1", `$1")') Shift –Looks at all arguments except the first one

For loop Forloop(valName,start, end, statement) In actuality a recursive call –No real implementation for loops define(`forloop', `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')') define(`_forloop', `$4`'ifelse($1, `$3',, `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')

String Manipulation Len(string1) Substr(string1,pos,#ofchars) Index(string1,string2) Translit(string,set1,set2) –Can use regular expressions –Example patsubst(`GNUs not Unix', `[A-Z][a-z]+')

References temhttp://en.wikipedia.org/wiki/GNU_build_sys tem tem#GNU_Automakehttp://en.wikipedia.org/wiki/GNU_build_sys tem#GNU_Automake /m4.htmlhttp:// /m4.html concepts/autotools/