Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Integer Literals chapter #208

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion specs/language/lex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,86 @@
vector-literal
\end{grammar}

%\Sub{Integer Literals}{Lex.Literal.Int}
\Sub{Integer Literals}{Lex.Literal.Int}

\begin{grammar}
\define{integer-literal}\br
decimal-literal \opt{integer-suffix}\br
octal-literal \opt{integer-suffix}\br
hexadecimal-literal \opt{integer-suffix}\br

\define{decimal-literal}\br
nonzero-digit\br
decimal-literal digit\br

\define{octal-literal}
\terminal{0}\br
octal-literal octal-digit\br

\define{hexadecimal-literal}\br
\terminal{0x} hexadecimal-digit\br
\terminal{0X} hexadecimal-digit\br
hexadecimal-literal hexadecimal-digit\br

\define{nonzero-digit} \textnormal{one of}\br
\terminal{1 2 3 4 5 6 7 8 9}\br

\define{octal-digit} \textnormal{one of}\br
\terminal{0 1 2 3 4 5 6 7}\br

\define{hexadecimal-digit} \textnormal{one of}\br
\terminal{0 1 2 3 4 5 6 7 8 9}\br
\terminal{a b c d e f}\br
\terminal{A B C D E F}\br

\define{integer-suffix}\br
unsigned-suffix \opt{long-suffix}\br
long-suffix \opt{unsigned-suffix}\br

\define{unsigned-suffix} \textnormal{one of}\br
\terminal{u U}\br

\define{long-suffix} \textnormal{one of}\br
\terminal{l L}
\end{grammar}

\p An \textit{integer literal} is an optional base prefix, a sequence of digits
in the appropriate base, and an optional type suffix. An integer literal shall
not contain a period or exponent specifier.

\p The type of an integer literal is the first of the corresponding list in the
table below in which its value can be represented\footnote{This behavior matches
\gls{isoC} but is reduced in scope because HLSL has fewer data types.}.

\begin{center}
\begin{tabular}{|| c | c | c ||}
\hline
Suffix & Decimal constant & Octal or hexadecimal constant \\
\hline
\hline
none & \texttt{int32\_t} & \texttt{int32\_t} \\
& \texttt{int64\_t} & \texttt{uint32\_t} \\
& & \texttt{int64\_t} \\
& & \texttt{uint64\_t} \\
\hline
\texttt{u} or \texttt{U} & \texttt{uint32\_t} & \texttt{uint32\_t} \\
& \texttt{uint64\_t} & \texttt{uint64\_t} \\
\hline
\texttt{l} or \texttt{L} & \texttt{int64\_t} & \texttt{int64\_t} \\
& & \texttt{uint64\_t} \\
\hline
Both \texttt{u} or \texttt{U} & \texttt{uint64\_t} & \texttt{uint64\_t} \\
and \texttt{l} or \texttt{L} & & \\
\hline
\end{tabular}
\end{center}

\p If the specified value of an integer literal cannot be represented by any
type in the corresponding list, the integer literal has no type and the program
is ill-formed.

\p An implementation may support the integer suffixes \texttt{ll} and
\texttt{ull} as equivalent to \texttt{l} and \texttt{ul} respectively.

%\Sub{Character Literals}{Lex.Literal.Char}

Expand Down
Loading