Skip to content
246 changes: 143 additions & 103 deletions source/preprocessor.tex
Original file line number Diff line number Diff line change
Expand Up @@ -47,53 +47,15 @@

\begin{bnf}
\nontermdef{control-line}\br
\terminal{\# include} pp-tokens new-line\br
include-directive\br
pp-import\br
\terminal{\# embed \ } pp-tokens new-line\br
\terminal{\# define } identifier replacement-list new-line\br
\terminal{\# define } identifier lparen \opt{identifier-list} \terminal{)} replacement-list new-line\br
\terminal{\# define } identifier lparen \terminal{... )} replacement-list new-line\br
\terminal{\# define } identifier lparen identifier-list \terminal{, ... )} replacement-list new-line\br
\terminal{\# undef \ } identifier new-line\br
\terminal{\# line \ \ } pp-tokens new-line\br
\terminal{\# error \ } \opt{pp-tokens} new-line\br
\terminal{\# warning} \opt{pp-tokens} new-line\br
\terminal{\# pragma } \opt{pp-tokens} new-line\br
\terminal{\# }new-line
\end{bnf}

\begin{bnf}
\nontermdef{if-section}\br
if-group \opt{elif-groups} \opt{else-group} endif-line
\end{bnf}

\begin{bnf}
\nontermdef{if-group}\br
\terminal{\# if \ \ \ \ } constant-expression new-line \opt{group}\br
\terminal{\# ifdef \ } identifier new-line \opt{group}\br
\terminal{\# ifndef } identifier new-line \opt{group}
\end{bnf}

\begin{bnf}
\nontermdef{elif-groups}\br
elif-group \opt{elif-groups}
\end{bnf}

\begin{bnf}
\nontermdef{elif-group}\br
\terminal{\# elif \ \ \ } constant-expression new-line \opt{group}\br
\terminal{\# elifdef } identifier new-line \opt{group}\br
\terminal{\# elifndef} identifier new-line \opt{group}
\end{bnf}

\begin{bnf}
\nontermdef{else-group}\br
\terminal{\# else \ \ } new-line \opt{group}
\end{bnf}

\begin{bnf}
\nontermdef{endif-line}\br
\terminal{\# endif \ } new-line
embed-directive\br
define-directive\br
undef-directive\br
line-directive\br
diagnostic-directive\br
pragma-directive\br
null-directive
\end{bnf}

\begin{bnf}
Expand All @@ -106,68 +68,11 @@
pp-tokens new-line
\end{bnf}

\begin{bnf}
\nontermdef{lparen}\br
\descr{a \terminal{(} character not immediately preceded by whitespace}
\end{bnf}

\begin{bnf}
\nontermdef{identifier-list}\br
identifier\br
identifier-list \terminal{,} identifier
\end{bnf}

\begin{bnf}
\nontermdef{replacement-list}\br
\opt{pp-tokens}
\end{bnf}

\begin{bnf}
\nontermdef{pp-tokens}\br
preprocessing-token \opt{pp-tokens}
\end{bnf}

\begin{bnf}
\nontermdef{embed-parameter-seq}\br
embed-parameter \opt{embed-parameter-seq}
\end{bnf}

\begin{bnf}
\nontermdef{embed-parameter}\br
embed-standard-parameter\br
embed-prefixed-parameter
\end{bnf}

\begin{bnf}
\nontermdef{embed-standard-parameter}\br
\terminal{limit} \terminal{(} pp-balanced-token-seq \terminal{)}\br
\terminal{prefix} \terminal{(} \opt{pp-balanced-token-seq} \terminal{)}\br
\terminal{suffix} \terminal{(} \opt{pp-balanced-token-seq} \terminal{)}\br
\terminal{if_empty} \terminal{(} \opt{pp-balanced-token-seq} \terminal{)}
\end{bnf}

\begin{bnf}
\nontermdef{embed-prefixed-parameter}\br
identifier :: identifier\br
identifier :: identifier \terminal{(} \opt{pp-balanced-token-seq} \terminal{)}
\end{bnf}

\begin{bnf}
\nontermdef{pp-balanced-token-seq}\br
pp-balanced-token \opt{pp-balanced-token-seq}
\end{bnf}

\begin{bnf}
\nontermdef{pp-balanced-token}\br
\terminal{(} \opt{pp-balanced-token-seq} \terminal{)}\br
\terminal{[} \opt{pp-balanced-token-seq} \terminal{]}\br
\terminal{\{} \opt{pp-balanced-token-seq} \terminal{\}}\br
\textnormal{any} pp-token \textnormal{except:}\br
\bnfindent\textnormal{parenthesis (\unicode{0028}{left parenthesis} and \unicode{0029}{right parenthesis}),}\br
\bnfindent\textnormal{bracket (\unicode{005b}{left square bracket} and \unicode{005d}{right square bracket}), or}\br
\bnfindent\textnormal{brace (\unicode{007b}{left curly bracket} and \unicode{007d}{right curly bracket}).}
\end{bnf}

\begin{bnf}
\nontermdef{new-line}\br
\descr{the new-line character}
Expand Down Expand Up @@ -335,6 +240,40 @@
\indextext{preprocessing directive!conditional inclusion}%
\indextext{inclusion!conditional|see{preprocessing directive, conditional inclusion}}

\begin{bnf}
\nontermdef{if-section}\br
if-group \opt{elif-groups} \opt{else-group} endif-line
\end{bnf}

\begin{bnf}
\nontermdef{if-group}\br
\terminal{\# if \ \ \ \ } constant-expression new-line \opt{group}\br
\terminal{\# ifdef \ } identifier new-line \opt{group}\br
\terminal{\# ifndef } identifier new-line \opt{group}
\end{bnf}

\begin{bnf}
\nontermdef{elif-groups}\br
elif-group \opt{elif-groups}
\end{bnf}

\begin{bnf}
\nontermdef{elif-group}\br
\terminal{\# elif \ \ \ } constant-expression new-line \opt{group}\br
\terminal{\# elifdef } identifier new-line \opt{group}\br
\terminal{\# elifndef} identifier new-line \opt{group}
\end{bnf}

\begin{bnf}
\nontermdef{else-group}\br
\terminal{\# else \ \ } new-line \opt{group}
\end{bnf}

\begin{bnf}
\nontermdef{endif-line}\br
\terminal{\# endif \ } new-line
\end{bnf}

\indextext{\idxcode{defined}}%
\begin{bnf}
\nontermdef{defined-macro-expression}\br
Expand Down Expand Up @@ -696,6 +635,11 @@
\indextext{inclusion!source file|see{preprocessing directive, source-file inclusion}}%
\indextext{\idxcode{\#include}}%

\begin{bnf}
\nontermdef{include-directive}\br
\terminal{\# include} pp-tokens new-line\br
\end{bnf}

\pnum
A \defnadj{header}{search} for a sequence of characters
searches a sequence of places for a header
Expand Down Expand Up @@ -845,6 +789,52 @@
\indextext{preprocessing directive!embed a resource}
\indextext{\idxcode{\#embed}}%

\begin{bnf}
\nontermdef{embed-directive}\br
\terminal{\# embed \ } pp-tokens new-line\br
\end{bnf}

\begin{bnf}
\nontermdef{embed-parameter-seq}\br
embed-parameter \opt{embed-parameter-seq}
\end{bnf}

\begin{bnf}
\nontermdef{embed-parameter}\br
embed-standard-parameter\br
embed-prefixed-parameter
\end{bnf}

\begin{bnf}
\nontermdef{embed-standard-parameter}\br
\terminal{limit} \terminal{(} pp-balanced-token-seq \terminal{)}\br
\terminal{prefix} \terminal{(} \opt{pp-balanced-token-seq} \terminal{)}\br
\terminal{suffix} \terminal{(} \opt{pp-balanced-token-seq} \terminal{)}\br
\terminal{if_empty} \terminal{(} \opt{pp-balanced-token-seq} \terminal{)}
\end{bnf}

\begin{bnf}
\nontermdef{embed-prefixed-parameter}\br
identifier :: identifier\br
identifier :: identifier \terminal{(} \opt{pp-balanced-token-seq} \terminal{)}
\end{bnf}

\begin{bnf}
\nontermdef{pp-balanced-token-seq}\br
pp-balanced-token \opt{pp-balanced-token-seq}
\end{bnf}

\begin{bnf}
\nontermdef{pp-balanced-token}\br
\terminal{(} \opt{pp-balanced-token-seq} \terminal{)}\br
\terminal{[} \opt{pp-balanced-token-seq} \terminal{]}\br
\terminal{\{} \opt{pp-balanced-token-seq} \terminal{\}}\br
\textnormal{any} pp-token \textnormal{except:}\br
\bnfindent\textnormal{parenthesis (\unicode{0028}{left parenthesis} and \unicode{0029}{right parenthesis}),}\br
\bnfindent\textnormal{bracket (\unicode{005b}{left square bracket} and \unicode{005d}{right square bracket}), or}\br
\bnfindent\textnormal{brace (\unicode{007b}{left curly bracket} and \unicode{007d}{right curly bracket}).}
\end{bnf}

\rSec2[cpp.embed.gen]{General}

\pnum
Expand Down Expand Up @@ -1445,6 +1435,35 @@
\indextext{replacement!macro|see{macro, replacement}}%
\indextext{preprocessing directive!macro replacement|see{macro, replacement}}

\begin{bnf}
\nontermdef{define-directive}\br
\terminal{\# define } identifier replacement-list new-line\br
\terminal{\# define } identifier lparen \opt{identifier-list} \terminal{)} replacement-list new-line\br
\terminal{\# define } identifier lparen \terminal{... )} replacement-list new-line\br
\terminal{\# define } identifier lparen identifier-list \terminal{, ... )} replacement-list new-line\br
\end{bnf}

\begin{bnf}
\nontermdef{undef-directive}\br
\terminal{\# undef \ } identifier new-line\br
\end{bnf}

\begin{bnf}
\nontermdef{lparen}\br
\descr{a \terminal{(} character not immediately preceded by whitespace}
\end{bnf}

\begin{bnf}
\nontermdef{identifier-list}\br
identifier\br
identifier-list \terminal{,} identifier
\end{bnf}

\begin{bnf}
\nontermdef{replacement-list}\br
\opt{pp-tokens}
\end{bnf}

\pnum
\indextext{macro!replacement list}%
Two replacement lists are identical if and only if
Expand Down Expand Up @@ -2070,6 +2089,11 @@
\indextext{preprocessing directive!line control}%
\indextext{\idxcode{\#line}|see{preprocessing directive, line control}}

\begin{bnf}
\nontermdef{line-directive}\br
\terminal{\# line \ \ } pp-tokens new-line\br
\end{bnf}

\pnum
The \grammarterm{string-literal} of a
\tcode{\#line}
Expand Down Expand Up @@ -2130,6 +2154,12 @@
\indextext{preprocessing directive!warning}%
\indextext{\idxcode{\#error}|see{preprocessing directive, error}}

\begin{bnf}
\nontermdef{diagnostic-directive}\br
\terminal{\# error \ } \opt{pp-tokens} new-line\br
\terminal{\# warning} \opt{pp-tokens} new-line\br
\end{bnf}

\pnum
A preprocessing directive of the form
\begin{ncsimplebnf}
Expand All @@ -2152,6 +2182,11 @@
\indextext{preprocessing directive!pragma}%
\indextext{\idxcode{\#pragma}|see{preprocessing directive, pragma}}

\begin{bnf}
\nontermdef{pragma-directive}\br
\terminal{\# pragma } \opt{pp-tokens} new-line\br
\end{bnf}

\pnum
A preprocessing directive of the form
\begin{ncsimplebnf}
Expand All @@ -2166,6 +2201,11 @@
\rSec1[cpp.null]{Null directive}%
\indextext{preprocessing directive!null}

\begin{bnf}
\nontermdef{null-directive}\br
\terminal{\# }new-line
\end{bnf}

\pnum
A preprocessing directive of the form
\begin{ncsimplebnf}
Expand Down