% Stolen from stackexchange: calculate indent based on given keyword,
% with some nice hrules added in.
\newlength{\myl}
\newenvironment{indentgrammar}[1]
{\vspace{0.5cm}\hrule
\setlength{\myl}{\widthof{#1}+2em}
\grammarindent\the\myl
\begin{grammar}}
{\end{grammar}
\hrule}
This appendix documents the text representation of RTLIL in extended Backus-Naur form (EBNF).
The grammar is not meant to represent semantic limitations. For example, processes must contain exactly one switch statement, but the grammar allows zero or more than one. That is, the grammar is "permissive", and later stages of processing perform more rigorous checks.
The grammar is also not meant to represent the exact grammar used in the RTLIL frontend, since that grammar is specific to processing by lex and yacc, and is somewhat less understandable than simple EBNF notation.
\section{Lexical elements}
\subsection{Identifiers}
There are three types of identifiers in RTLIL:
\begin{itemize}
\item Publically visible identifiers
\item Auto-generated identifiers
\item Dotted numeric identifiers
\end{itemize}
\begin{indentgrammar}{<autogen-id>}
<id> ::= <public-id> | <autogen-id> | <dotted-id>
<public-id> ::= "\textbackslash" <nonws>$+$
<autogen-id> ::= "\textdollar" <nonws>$+$
<dotted-id> ::= "." <decimal-digit>$+$
\end{indentgrammar}
\subsection{Values}
A \textit{value} consists of a width in bits and a bit representation, most significant bit first. Bits may be any of:
A module consists of zero or more module statements.
\begin{indentgrammar}{<module-stmt>}
<module> ::= "module" <id> <eol> <module-stmt>$*$
<module-stmt> ::=
<param-stmt>
\alt <attr-stmt>
\alt <wire-stmt>
\alt <memory-stmt>
\alt <cell-stmt>
\alt <proc-stmt>
\alt <conn-stmt>
\end{indentgrammar}
\subsection{Signal specifications}
A signal is anything that can be applied to a cell port, i.e. a constant value, all bits or a selection of bits from a wire, or concatenations of those.
See Sec.~\ref{sec:rtlil_sigspec} for an overview of signal specifications.