Pascal Preprocessor |
A |
![]() |
__sun |
__SVR4 |
sparc |
__sparc |
__SUNPRO_PC=0x400 |
unix |
__unix |
sun |
|
These variables are not predefined when you use -s0, -s1, -V0, or -V1.
%var one two %enable two |
The following section describes %var and %enable. Programs that contain conditional variables must be compiled with the -xl option.
Compiler Directives
A directive indicates some action for the compiler to take. You can use a directive anywhere in your program.
The rest of this appendix contains detailed descriptions and examples of each directive.
The %config Directive
The %config directive is a predefined conditional variable with a value of either true or false. Syntax
%config Comments
%config is true when you compile your program with the -config option; otherwise, %config is false. Example
The output when you compile config.p without the -config option
|
hostname% pc -xl config.p hostname% a.out Begin program. End program. |
The output when you define the variable one
|
hostname% pc -xl -config one config.p hostname% a.out Begin program. One is defined as 32767. End program. |
The output when you define two
|
hostname% pc -xl -config two config.p hostname% a.out Begin program. Two is defined as -32768. End program. |
The output when you define foo
|
hostname% pc -xl -config foo config.p Fri Mar 3 15:22 1995 config.p Error: -CONFIG command argument foo was never declared. Compilation failed |
The %debug Directive
The %debug directive instructs pc to compile this line of code when you use the -cond compiler directive. Syntax
%debug; Comments
The %debug directive works in conjunction with the -cond compiler option.
-cond causes pc to compile the lines in your program that begin with %debug. Without -cond, pc treats lines with %debug as comments. Example
The output when you compile debug.p without the -cond option
|
hostname% pc -xl debug.p hostname% a.out Hello, how are you? |
The output when you use -cond
|
hostname% pc -xl -cond debug.p hostname% a.out Hello, how are you? Fine, thank you. |
The %else Directive
The %else directive provides an alternative action to the %if directive. Syntax
%if expression %then
.
.
%else
.
.
%endif Example
The Pascal program, if_then_else.p
|
program if_then_else (output); %var red begin %if red %then writeln ('It is red.'); %else writeln ('It is not red.') %endif end. |
The output when you compile if_then_else.p without the -config
|
hostname% pc -xl if_then_else.p hostname% a.out It is not red. |
The output when you supply -config with the argument red
|
hostname% pc -xl -config red if_then_else.p hostname% a.out It is red. |
The %elseif Directive
The %elseif directive provides an alternative action to the %if directive. Syntax
%if expression %then
.
.
%elseif expression %then
.
.
%endif Comments
If the expression in %if expression %then is false, pc skips over the %then part and executes the %elseif part instead. expression consists of a conditional variable and the optional boolean operators, and, or, and not. See the %else listing for examples of expression. Example
The output when you supply -config with the argument blue
|
hostname% pc -xl -config blue elseif.p hostname% a.out The color is blue. |
The output when you supply -config with the argument red
|
hostname% pc -xl -config red elseif.p hostname% a.out The color is red. |
The %elseifdef Directive
The %elseifdef directive provides an alternative action to the %ifdef directive. Syntax
%ifdef expression %then
.
.
%elseifdef expression %then
.
.
%endif Comments
If the expression in %ifdef expression %then is false, pc skips over the %then part and executes the %elseifdef part instead. expression consists of a conditional variable and the optional boolean operators, and, or, and not. See the %else listing for examples of expression. Example
The include file, bird.h
|
var a: array[1..7] of char := 'penguin'; b: array[1..6] of char := 'toucan'; %var bird1 |
The output when you enable bird1 with the -config option
|
hostname% pc -xl -config bird1 ifdef.p hostname% a.out Bird two is a penguin. |
The output when you enable bird2 with the -config option
|
hostname% pc -xl -config bird2 ifdef.p hostname% a.out Bird two is a toucan. |
The %enable Directive
The %enable directive sets a conditional variable to true. Syntax
%enable var1 ..., varN Comments
A defined conditional variable is enable (true) when it appears in either the %enable directive or in the -config option. Conditional variables are false by default. Example
The commands to compile and output enable.p
|
hostname% pc -xl enable.p hostname% a.out Two is defined as -32768. |
The %endif Directive
The %endif directive indicates the end of a %if or %ifdef directive. See the sections on %if and %ifdef for more information on this directive. The %error Directive
The %error directive causes the compiler to print a string on the standard output and treat it as an error. Syntax
%error 'string' Comments
pc does not produce an object file. Example
The %exit Directive
The %exit directive instructs the compiler to stop processing the current Pascal source file. Syntax
%exit Comments
If the compiler encounters an %exit directive within an include file, it stops processing the include file, but continues processing the source file in which it is included. In effect, %exit is equivalent to an end-of-file marker. Example
The Pascal program, exit_directive.p
|
program exit_directive(output); begin writeln('Hello, world!') end. { exit_directive } %exit Everything after the %exit is ignored. So you can put anything here. |
The commands to compile and execute exit_directive.p
|
hostname% pc -xl exit_directive.p hostname% a.out Hello, world! |
The %if Directive
The %if directive is a conditional branching directive. Syntax
%if expression %then
.
.
%end if Comments
When pc encounters a %if directive, it evaluates expression. If expression is true, pc executes the statements in the %then part. If expression is false, pc skips over the %then part and executes the %else, %elseif, or %endif directive. If no such directive exists, pc proceeds to the next statement.
Assuming one and two are conditional variables, expression can be any of the following:
one
two
one and two
one or two
not one
not two
Example
See the example in the %else listing on page 258.
The %ifdef Directive
The %ifdef directive determines whether or not you previously defined a conditional variable in a %var directive. Syntax
%ifdef expression %then
.
.
%elseifdef expression %then
.
.
%endif Comments
expression consists of a conditional variable and the optional boolean operators and, or, and not. See the %else listing for examples of expression. Example
See the example in "The %elseifdef Directive."
The %include Directive
The %include directive inserts lines from the specified file in the input stream. Syntax
%include 'filename'; Comments
When cppas encounters the %include directive, it inserts the lines from the file name into the input stream. Example
The module unit, include_mod.p
|
module include_mod; define global, proc; %include 'extern.h'; procedure proc; begin writeln('From PROC : ',global); global := global + 1; end; { proc } |
The include file, include.h
|
var global : integer; procedure proc; extern; |
The %list Directive
The %list directive enables a listing of the program. Syntax
%list; Comments
The %list directive and the -l compiler option perform the same function. Example
The %nolist Directive
The %nolist directive disables the program listing. Syntax
%nolist; Comments
%nolist is the default. Example
See the example under "The %list Directive."
The %slibrary Directive
cppas treats %slibrary in the same manner as the %include directive. See "The %include Directive" on page 267.
The %var Directive
The %var directive defines conditional variables for the preprocessor. Syntax
%var var1 ..., varN Comments
A conditional variable is defined when it appears in a %var directive; otherwise, it is undefined. Example
See the example under "The %config Directive" on page 255.
The %warning Directive
The %warning directive instructs pc to print a string on the standard output as a compiler warning. Syntax
%warning 'string' Comments
pc produces an object file. Example