Intel XENIX 286 Programmers Guide (86) - Tenox.tc
Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc
CHAPTER 11 m4: MACRO PROCESSOR The m4 macro processor defines and processes specially defined strings of characters called macros. By defining a set of macros to be processed by m4, a programming language can be enhanced to make it more structured, more readable, and more appropriate for a particular application. The #define statement in C and the analogous define in RATFOR are examples of the basic facility provided by any macro processor--replacement of text by other text. Besides the straightforward replacement of one string of text by another, m4 provides • Macros with arguments • Conditional macro expansions • Arithmetic expressions • File manipulation facilities • String processing functions The basic operation of m4 is copying its input to its output. As the input is read, each alphanumeric token (that is, string of letters and digits) is checked. If the token is the name of a macro, then the name of the macro is replaced by its defining text. The resulting string is reread by m4. Macros may also be called with arguments, in which case the arguments are collected and substituted in the right places in the defining text before m4 rescans the text. m4 provides a collection of about 20 built-in macros. In addition, the user can define new macros. Built-in and user-defined macros work in exactly the same way, except that some of the built-in macros have side effects on the state of the process. 11-1
m4: Macro Processor XENIX Programming Invoking m4 The invocat ion syntax for m4 is m4 [ filename ] . .. Each filename argument is processed in order. If there are no arguments, or ·if an argument is a dash (-), then the standard input is read. The processed text is written to the standard output and can be redirected as in the following example: m4 file1 file2 - >outputfi le Note the use of the dash in the above example to indicate processing of the standard input, after the files filel and file2 have been processed by m4. Defining Macros The primary built-in function of m4 is define, which is used to define new macros. The input define(name, stuff) causes the string name to be defined as stuff. All subsequent occurrences of name will be replaced by stuff. name must be alphanumeric and must begin with a letter (the underscore ( ) counts as a letter). stuff is any text, including text that contains balanced parentheses; it may stretch over multiple lines. Thus, as a typical example defi ne(N, 1 00) if (i > N) defines N to be 100 and uses this symbolic constant in a later if statement. The left parenthesis must immediately follow the word define, to signal that define has arguments. If a macro or built-in name is not followed immediately by a left parenthesis, it is assumed to have no arguments. This is the situation for N above; it is actually a macro with no arguments. Thus, when it is used, no parentheses are needed following its name. 11-2
- Page 190 and 191: XENIX Programming lex: Lexical Anal
- Page 192 and 193: XENIX Programm ing lex: Lexical Ana
- Page 194 and 195: XENIX Programming Specifying Source
- Page 196 and 197: XENIX Programming lex: Lexical Anal
- Page 198 and 199: XENIX Programming lex: Lexical Anal
- Page 200 and 201: XENIX Programming The definitions s
- Page 202 and 203: CHAPTER 10 yacc: COMPILER-COMPILER
- Page 204 and 205: XENIX Programming yacc: Compiler-Co
- Page 206 and 207: XENIX Programming yacc: Compiler-Co
- Page 208 and 209: XENIX Programming yacc: Compiler-Co
- Page 210 and 211: XENIX Programming yacc: Compiler-Co
- Page 212 and 213: XENIX Programming yacc: Compiler-Co
- Page 214 and 215: XENIX Programming yacc: Compiler-Co
- Page 216 and 217: XENIX Programming yacc: Compiler-Co
- Page 218 and 219: XENIX Programming yacc: Compiler-Co
- Page 220 and 221: XENIX Programming yacc: Compiler-Co
- Page 222 and 223: XENIX Programming yacc: Compiler-Co
- Page 224 and 225: XENIX Programming yacc: Compiler-Co
- Page 226 and 227: XENIX Programming yacc: Compiler-Co
- Page 228 and 229: XENIX Programming yacc: Compiler-Co
- Page 230 and 231: XENIX Programming yacc: Compiler-Co
- Page 232 and 233: XENIX Programming yacc: Compiler-Co
- Page 234 and 235: XENIX Programming yacc: Compiler-Co
- Page 236 and 237: XENIX Programming %left %left %left
- Page 238 and 239: XENIX Programming I* lexical analys
- Page 240: XENIX Programming yacc: Compiler-Co
- Page 245 and 246: m4: Macro Processor XENIX Programmi
- Page 247 and 248: m4: Macro Processor XENIX Programm
- Page 249 and 250: m4: Macro Processor XENIX Programmi
- Page 251 and 252: m4: Macro Processor XENIX Programmi
- Page 253 and 254: C Language Portability XENIX Progra
- Page 255 and 256: C Language Portability XENIX Progra
- Page 257 and 258: C Language Portability XENIX Progra
- Page 259 and 260: C Language Portability XENIX Progra
- Page 261 and 262: C Language Portability XENIX Progra
- Page 263 and 264: C Language Portability XENIX Progra
- Page 266 and 267: APPENDIX B PROG RAMMING COMMANDS Th
- Page 268 and 269: XENIX Programming ad b (continued)
- Page 270 and 271: XENIX Programming Programming Comma
- Page 272 and 273: XENIX Programming Programming Comma
- Page 274 and 275: XENIX Programming Programming Comma
- Page 276 and 277: XENIX Programming Programming Comma
- Page 278 and 279: XENIX Programming Programming Comma
- Page 280 and 281: XENIX Programming Programming Comma
- Page 282 and 283: XENIX Programming Programming Comma
- Page 284 and 285: XENIX Programming as (continued) Fi
- Page 286 and 287: XENIX Programming Programming Comma
- Page 288 and 289: XENIX Programming Programming Comma
- Page 290 and 291: XENIX Programming Programm ing Comm
CHAPTER 11<br />
m4: MACRO PROCESSOR<br />
The m4 macro processor defines and processes specially defined strings of characters<br />
called macros. By defining a set of macros to be processed by m4, a programming<br />
language can be enhanced to make it more structured, more readable, and more<br />
appropriate for a particular application.<br />
The #define statement in C and the analogous define in RATFOR are examples of the<br />
basic facility provided by any macro processor--replacement of text by other text.<br />
Besides the straightforward replacement of one string of text by another, m4 provides<br />
• Macros with arguments<br />
• Conditional macro expansions<br />
• Arithmetic expressions<br />
• File manipulation facilities<br />
• String processing functions<br />
The basic operation of m4 is copying its input to its output. As the input is read, each<br />
alphanumeric token (that is, string of letters and digits) is checked. If the token is the<br />
name of a macro, then the name of the macro is replaced by its defining text. The<br />
resulting string is reread by m4. Macros may also be called with arguments, in which<br />
case the arguments are collected and substituted in the right places in the defining text<br />
before m4 rescans the text.<br />
m4 provides a collection of about 20 built-in macros. In addition, the user can define<br />
new macros. Built-in and user-defined macros work in exactly the same way, except<br />
that some of the built-in macros have side effects on the state of the process.<br />
11-1