--- title: "Preprocessor grammar summary (C/C++)" description: "Defines and describes the Microsoft C/C++ compiler (MSVC) preprocessor grammar syntax." ms.date: 01/22/2021 helpviewer_keywords: ["grammar", "preprocessor, grammar"] --- # Preprocessor grammar summary (C/C++) This article describes the formal grammar of the C and C++ preprocessor. It covers the syntax of preprocessing directives and operators. For more information, see [Preprocessor](../preprocessor/preprocessor.md) and [Pragma directives and the `__pragma` and `_Pragma` keywords](./pragma-directives-and-the-pragma-keyword.md). ## Definitions for the grammar summary Terminals are endpoints in a syntax definition. No other resolution is possible. Terminals include the set of reserved words and user-defined identifiers. Nonterminals are placeholders in the syntax. Most are defined elsewhere in this syntax summary. Definitions can be recursive. The following nonterminals are defined in the [Lexical conventions](../cpp/lexical-conventions.md) section of the *C++ Language Reference*: *`constant`*, *`constant-expression`*, *`identifier`*, *`keyword`*, *`operator`*, *`punctuator`* An optional component is indicated by the subscripted opt. For example, the following syntax indicates an optional expression enclosed in curly braces: **`{`** *`expression`*opt **`}`** ## Document conventions The conventions use different font attributes for different components of the syntax. The symbols and fonts are as follows: | Attribute | Description | |---------------|-----------------| | *`nonterminal`* | Italic type indicates nonterminals. | | **`#include`** | Terminals in bold type are literal reserved words and symbols that must be entered as shown. Characters in this context are always case sensitive. | | opt | Nonterminals followed by opt are always optional.| | default typeface | Characters in the set described or listed in this typeface can be used as terminals in statements. | A colon (**`:`**) following a nonterminal introduces its definition. Alternative definitions are listed on separate lines. In code syntax blocks, these symbols in the default typeface have a special meaning: | Symbol | Description | |---|---| | \[ ] | Square brackets surround an optional element. | | { \| } | Curly braces surround alternative elements, separated by vertical bars. | | ... | Indicates the previous element pattern can be repeated. | In code syntax blocks, commas (`,`), periods (`.`), semi-colons (`;`), colons (`:`), parentheses (`( )`), double-quotes (`"`), and single-quotes (`'`) are literals. ## Preprocessor grammar *`control-line`*:\  **`#define`** *`identifier`* *`token-string`*opt\  **`#define`** *`identifier`* **`(`** *`identifier`*opt **`,`** ... **`,`** *`identifier`*opt **`)`** *`token-string`*opt\  **`#include`** **`"`**_`path-spec`_**`"`**\  **`#include`** **`<`**_`path-spec`_**`>`**\  **`#line`** *`digit-sequence`* **`"`**_`filename`_**`"`**opt\  **`#undef`** *`identifier`*\  **`#error`** *`token-string`*\  **`#pragma`** *`token-string`* *`constant-expression`*:\  **`defined(`** *`identifier`* **`)`**\  **`defined`** *`identifier`*\  any other constant expression *`conditional`*:\  *`if-part`* *`elif-parts`*opt *`else-part`*opt *`endif-line`* *`if-part`*:\  *`if-line`* *`text`* *`if-line`*:\  **`#if`** *`constant-expression`*\  **`#ifdef`** *`identifier`*\  **`#ifndef`** *`identifier`* *`elif-parts`*:\  *`elif-line`* *`text`*\  *`elif-parts`* *`elif-line`* *`text`* *`elif-line`*:\  **`#elif`** *`constant-expression`* *`else-part`*:\  *`else-line`* *`text`* *`else-line`*:\  **`#else`** *`endif-line`*:\  **`#endif`** *`digit-sequence`*:\  *`digit`*\  *`digit-sequence`* *`digit`* *`digit`*: one of\  **`0` `1` `2` `3` `4` `5` `6` `7` `8` `9`** *`token-string`*:\  String of *`token`* *`token`*:\  *`keyword`*\  *`identifier`*\  *`constant`*\  *`operator`*\  *`punctuator`* *`filename`*:\  Legal operating system filename *`path-spec`*:\  Legal file path *`text`*:\  Any sequence of text > [!NOTE] > The following nonterminals are expanded in the [Lexical conventions](../cpp/lexical-conventions.md) section of the *C++ Language Reference*: *`constant`*, *`constant-expression`*, *`identifier`*, *`keyword`*, *`operator`*, and *`punctuator`*. ## See also [C/C++ preprocessor reference](../preprocessor/c-cpp-preprocessor-reference.md)