14.1 Introduction. 4tH 4tH Forth compiler
Реклама
Реклама
Chapter 14
Preprocessor libraries
14.1
Introduction
Some people start to frown when you mention preprocessors. But most don’t even realize that when you compile C, you’re always using a preprocessor - and with good reason!
Without a preprocessor you really wouldn’t want to write C, it would be awkward. C++ started its life as a preprocessor
1
. Several Forth compilers won’t even compile without a preprocessor. Face it: there is nothing wrong with preprocessors!
Preprocessors are wonderful tools to hide awful constructs under a silky smooth syntax, enhance your productivity, simplify maintenance and prevent programming errors. 4tH comes with a preprocessor
2 that is more powerful than C’s and shares many characteristics with M4
3
, like:
• Recursive macro expansion;
• Text replacement;
• Parameter substitution;
• File inclusion;
• Conditional evaluation;
• Arithmetic expressions.
In order to further enhance it, 4tH provides preprocessor libraries, which are in fact predefined macro’s. You use a preprocessor library like you would use an ordinary one, e.g.: include 4pp/lib/standard.4pp
After you’ve run the preprocessor, you compile as usual. Note there is no protection against including a preprocessor library twice, but on the other hand it won’t be included by (or include) other libraries, so that is pretty academic. If you’re running a Unix-like Operating
System, you could use make to make your life a little easier, e.g. by defining the following rules:
1 http://www2.research.att.com/~bs/hopl2.pdf
2
See chapter 18 for more information.
3 http://en.wikipedia.org/wiki/M4_%28computer_language%29
240
Изтегляне
Реклама