BARfly Help - BAR Implementation File Reference - Fundamental Components

  Preprocessor Directives

The BAR implementation file text format allows the use of preprocessor directives, which are identified by a number symbol as the first character of a line followed by a preprocessor name and possible additional information.  A line on which a preprocessor directive appears is reserved for only the preprocessor directive—no tokens or remarks can exist on the same line.

Preprocessor ::= ‘#’ (^(#10 | #13))* (#10 | #13))

Preprocessor directives are not themselves considered tokens.  This is because such directives are designed to influence compilation—they do not compose part of the final compilation of the file itself except as control flag definitions.

The “define” directive

DefineDirective ::= ‘#define’ S Identifier (S Token)?

This directive defines macros for use in the implementation file, normally for use as un-enumerated constants within the remainder of the file.  A “define” directive usually appears near the beginning of a file.

If no replacement token is present, the directive defines a macro token to have a replacement of the number 1.

The macro token must start with an underscore or alpha character, and the remainder of the token must consist of underscores and/or alphanumeric characters.  Future appearances of this token in the file will be replaced during compilation by the replacement token (or 1 if no replacement).

The replacement token is any type of token:  operator, punctuator, keyword, identifier, number, or string literal.  Whitespace must separate the macro token and replacement token.  The replacement cannot consist of more than one token.

The “define” directive can be used to set a control flag (for example, “BIGENDIAN”).  If the replacement is nonzero or unspecified, the control flag is set to true.  If the replacement is zero, the control flag is set to false.  All control flags start as false unless a “define” directive sets them as true.

Advanced macro functionality is not supported, including multi-token replacement, token pasting, and macro functions.

The “ifdef,” “ifndef,” “else,” and “endif” directives

IfdefDirective ::= ‘#ifdef’ S Identifier

This is a conditional compiling directive.  If the macro token was defined with the “define” macro, everything between this directive and the next “else” or “endif” directive is compiled.  If the macro token was not defined, everything between this directive and the next “else” or “endif” directive is ignored.

IfndefDirective ::= ‘#ifndef’ S Identifier

This is a conditional compiling directive.  If the macro token was defined with the “define” macro, everything between this directive and the next “else” or “endif” directive is ignored.  If the macro token was not defined, everything between this directive and the next “else” or “endif” directive is compiled.

ElseDirective ::= ‘#else’

This directive provides an alternate conditional compilation region to the “true” case in an “ifdef” or “ifndef” directive; all statements after “else” are compiled for a “false” case.

For “ifdef,” everything between this directive and the next “endif” directive is ignored.  For “ifndef,” everything between this directive and the next “endif” directive is compiled.

EndifDirective ::= ‘#endif’

This directive closes a conditional compilation region.  Every instance of “ifdef” or “ifndef” must be complemented with an “endif” directive.

It is possible to nest conditional compilation regions.  Each instance of “else” or “endif” directive only applies to the most recently declared “ifdef” or “ifndef” directive whose conditional compilation block is still open.

The “error” directive

ErrorDirective ::= ‘#error’ S (^(#10 | #13))* (#10 | #13)

This directive causes an error in compilation and writes custom error text (the text provided on the remainder of the line) to the compiler’s error log.

Use this directive when certain conditions about the compiling environment (e.g. some directives not defined properly) are inconsistent.

The “include” directive

IncludeDirective ::= ‘#include’ S (‘<’ | ‘”’) ([#32-#33] | [#35-#91] | [#93-#126])* (‘>’ | ‘”’) S? (#10 | #13)

This is a directive reserved for future use.  Currently, this directive is ignored.

The “pragma” directive

PragmaDirective ::= ‘#pragma’ S (^(#10 | #13))* (#10 | #13)

This is a directive reserved for future use.  Currently, this directive is ignored.

Unrecognized directives

UnrecognizedDirective ::= (‘#’ (^(#10 | #13))* (#10 | #13)) – (DefineDirective | IfdefDirective | IfndefDirective | ElseDirective | EndifDirective | ErrorDirective | IncludeDirective | PragmaDirective)

All other preprocessor directives cause an error in compilation.


  See also:  [Punctuators] [Operators] [Keywords]
[Identifiers] [Numbers] [String literals] [Remarks]
[Preprocessor directives] [Whitespace] [Unrecognized characters]


BARfly Help Copyright © 2009 Christopher Allen