\def\@scripts{\futurelet\@ch\@scripts@i}
\atdef ;#1\\{\normalfont\itshape;#1\\}
+\let\@@grammar\grammar
+\def\grammar{\def\textbar{\hbox{$|$}}\@@grammar}
\begingroup\lccode`\~=`\_\lowercase{\endgroup
\def\@scripts@i{\if1\ifx\@ch~1\else\ifx\@ch^1\else0\fi\fi%
\begin{quote}
$\epsilon$ ::=
\end{quote}
-\item $[$@<item>$]$ means an optional @<item>:
+\item @[@<item>@] means an optional @<item>:
\begin{quote}
- \syntax{$[$<item>$]$ ::= $\epsilon$ | <item>}
+ \syntax{@[<item>@] ::= $\epsilon$ @! <item>}
\end{quote}
-\item @<item>$^*$ means a sequence of zero or more @<item>s:
+\item @<item>^* means a sequence of zero or more @<item>s:
\begin{quote}
- \syntax{<item>$^*$ ::= $\epsilon$ | <item>$^*$ <item>}
+ \syntax{@<item>^* ::= $\epsilon$ @! @<item>^* <item>}
\end{quote}
-\item @<item>$^+$ means a sequence of one or more @<item>s:
+\item @<item>^+ means a sequence of one or more @<item>s:
\begin{quote}
- \syntax{<item>$^+$ ::= <item> <item>$^*$}
+ \syntax{@<item>^+ ::= <item> @<item>^*}
\end{quote}
\item @<item-list> means a sequence of one or more @<item>s separated
by commas:
\begin{quote}
- \syntax{<item-list> ::= <item> | <item-list> "," <item>}
+ \syntax{<item-list> ::= <item> @! <item-list> "," <item>}
\end{quote}
\end{itemize}
\subsubsection{Identifiers} \label{sec:syntax.lex.id}
\begin{grammar}
-<identifier> ::= <id-start-char> <id-body-char>$^*$
+<identifier> ::= <id-start-char> @<id-body-char>^*
-<id-start-char> ::= <alpha-char> $|$ "_"
+<id-start-char> ::= <alpha-char> | "_"
-<id-body-char> ::= <id-start-char> $|$ <digit-char>
+<id-body-char> ::= <id-start-char> @! <digit-char>
-<alpha-char> ::= "A" $|$ "B" $|$ \dots\ $|$ "Z"
-\alt "a" $|$ "b" $|$ \dots\ $|$ "z"
+<alpha-char> ::= "A" | "B" | \dots\ | "Z"
+\alt "a" | "b" | \dots\ | "z"
\alt <extended-alpha-char>
-<digit-char> ::= "0" $|$ <nonzero-digit-char>
+<digit-char> ::= "0" | <nonzero-digit-char>
-<nonzero-digit-char> ::= "1" $|$ "2" $| \cdots |$ "9"
+<nonzero-digit-char> ::= "1" | "2" $| \cdots |$ "9"
\end{grammar}
The precise definition of @<alpha-char> is left to the function
\begin{grammar}
<reserved-word> ::=
-"char" $|$ "class" $|$ "code" $|$ "const" $|$ "double" $|$ "enum" $|$
-"extern" $|$ "float" $|$ "import" $|$ "int" $|$ "lisp" $|$ "load" $|$ "long"
-$|$ "restrict" $|$ "short" $|$ "signed" $|$ "struct" $|$ "typename" $|$
-"union" $|$ "unsigned" $|$ "void" $|$ "volatile"
+"char" | "class" | "code" | "const" | "double" | "enum" |
+"extern" | "float" | "import" | "int" | "lisp" | "load" | "long"
+| "restrict" | "short" | "signed" | "struct" | "typename" |
+"union" | "unsigned" | "void" | "volatile"
\end{grammar}
Many of these are borrowed from~C; however, some (e.g., @"import" and
\subsubsection{String and character literals} \label{sec:syntax.lex.string}
\begin{grammar}
-<string-literal> ::= "\"" <string-literal-char>$^*$ "\""
+<string-literal> ::= "\"" @<string-literal-char>^* "\""
<char-literal> ::= "'" <char-literal-char> "'"
\alt <octal-integer>
\alt <hex-integer>
-<decimal-integer> ::= <nonzero-digit-char> <digit-char>$^*$
+<decimal-integer> ::= <nonzero-digit-char> @<digit-char>^*
-<binary-integer> ::= "0" $($"b"$|$"B"$)$ <binary-digit-char>$^+$
+<binary-integer> ::= "0" @("b"|"B"@) @<binary-digit-char>^+
-<binary-digit-char> ::= "0" $|$ "1"
+<binary-digit-char> ::= "0" | "1"
-<octal-integer> ::= "0" $[$"o"$|$"O"$]$ <octal-digit-char>$^+$
+<octal-integer> ::= "0" @["o"|"O"@] @<octal-digit-char>^+
-<octal-digit-char> ::= "0" $|$ "1" $| \cdots |$ "7"
+<octal-digit-char> ::= "0" | "1" $| \cdots |$ "7"
-<hex-integer> ::= "0" $($"x"$|$"X"$)$ <hex-digit-char>$^+$
+<hex-integer> ::= "0" @("x"|"X"@) @<hex-digit-char>^+
<hex-digit-char> ::= <digit-char>
-\alt "A" $|$ "B" $|$ "C" $|$ "D" $|$ "E" $|$ "F"
-\alt "a" $|$ "b" $|$ "c" $|$ "d" $|$ "e" $|$ "f"
+\alt "A" | "B" | "C" | "D" | "E" | "F"
+\alt "a" | "b" | "c" | "d" | "e" | "f"
\end{grammar}
Sod understands only integers, not floating-point numbers; its integer syntax
<block-comment> ::=
"/*"
- <not-star>$^*$ $($<star>$^+$ <not-star-or-slash> <not-star>$^*)^*$
- <star>$^*$
+ @<not-star>^* @(@<star>^+ <not-star-or-slash> @<not-star>^*@)^*
+ @<star>^*
"*/"
<star> ::= "*"
<not-star-or-slash> ::= any character other than "*" or "/"
-<line-comment> ::= "//" <not-newline>$^*$ <newline>
+<line-comment> ::= "//" @<not-newline>^* <newline>
<newline> ::= a newline character
\subsection{Module syntax} \label{sec:syntax-module}
\begin{grammar}
-<module> ::= <definition>$^*$
+<module> ::= @<definition>^*
<definition> ::= <import-definition>
\alt <load-definition>
\begin{grammar}
<code-definition> ::=
- "code" <identifier> ":" <identifier> $[$<constraints>$]$
+ "code" <identifier> ":" <identifier> @[<constraints>@]
"{" <c-fragment> "}"
<constraints> ::= "[" <constraint-list> "]"
-<constraint> ::= <identifier>$^+$
+<constraint> ::= @<identifier>^+
\end{grammar}
The @<c-fragment> will be output unchanged to one of the output files.
more @<qualifiers>, and one of the following, up to reordering.
\begin{itemize}
\item @<type-name>
-\item @"struct" <identifier>, @"union" <identifier>, @"enum" <identifier>
+\item @"struct" @<identifier>, @"union" @<identifier>, @"enum" @<identifier>
\item @"void"
\item @"char", @"unsigned char", @"signed char"
\item @"short", @"unsigned short", @"signed short"
\subsubsection{Declarators} \label{sec:syntax.c-types.declarator}
\begin{grammar}
-<declarator> ::=
- <pointer>$^*$ <inner-declarator> <declarator-suffix>$^*$
+<declarator>$[k]$ ::= @<pointer>^* <primary-declarator>$[k]$
-<inner-declarator> ::= <identifier> | <qualified-identifier>
-\alt "(" <declarator> ")"
+<primary-declarator>$[k]$ ::= $k$
+\alt "(" <primary-declarator>$[k]$ ")"
+\alt <primary-declarator>$[k]$ @<declarator-suffix>^*
-<qualified-identifier> ::= <identifier> "." <identifier>
-
-<pointer> ::= "*" <qualifier>$^*$
+<pointer> ::= "*" @<qualifier>^*
<declarator-suffix> ::= "[" <c-fragment> "]"
\alt "(" <arguments> ")"
-<arguments> ::= <empty> | "..."
-\alt <argument-list> $[$"," "..."$]$
+<arguments> ::= $\epsilon$ | "..."
+\alt <argument-list> @["," "..."@]
+
+<argument> ::= @<declaration-specifier>^+ <argument-declarator>
-<argument> ::= <declaration-specifier>$^+$ <argument-declarator>
+<argument-declarator> ::= <declarator>@[<identifier> @! $\epsilon$@]
-<argument-declarator> ::= <declarator> | $[$<abstract-declarator>$]$
+<simple-declarator> ::= <declarator>@[<identifier>@]
-<abstract-declarator> ::=
- <pointer>$^+$ | <pointer>$^*$ <inner-abstract-declarator>
+<dotted-name> ::= <identifier> "." <identifier>
-<inner-abstract-declarator> ::= "(" <abstract-declarator> ")"
-\alt $[$<inner-abstract-declarator>$]$ <declarator-suffix>$^+$
+<dotted-declarator> ::= <declarator>@[<dotted-name>@]
\end{grammar}
The declarator syntax is taken from C, but with some differences.
\begin{grammar}
<full-class-definition> ::=
- $[$<properties>$]$
+ @[<properties>@]
"class" <identifier> ":" <identifier-list>
- "{" <class-item>$^*$ "}"
+ "{" @<class-item>^* "}"
<class-item> ::= <slot-item> ";"
\alt <message-item>
\begin{grammar}
<slot-item> ::=
- $[$<properties>$]$
- <declaration-specifier>$^+$ <init-declarator-list>
+ @[<properties>@]
+ @<declaration-specifier>^+ <init-declarator-list>
-<init-declarator> ::= <declarator> $[$"=" <initializer>$]$
+<init-declarator> ::= <declarator> @["=" <initializer>@]
\end{grammar}
A @<slot-item> defines one or more slots. All instances of the class and any
\subsubsection{Initializer items} \label{sec:syntax.class.init}
\begin{grammar}
-<initializer-item> ::= $[$"class"$]$ <slot-initializer-list>
+<initializer-item> ::= @["class"@] <slot-initializer-list>
<slot-initializer> ::= <qualified-identifier> "=" <initializer>
\begin{grammar}
<message-item> ::=
- $[$<properties>$]$
- <declaration-specifier>$^+$ <declarator> $[$<method-body>$]$
+ @[<properties>@]
+ @<declaration-specifier>^+ <declarator> @[<method-body>@]
\end{grammar}
\subsubsection{Method items} \label{sec:syntax.class.method}
\begin{grammar}
<method-item> ::=
- $[$<properties>$]$
- <declaration-specifier>$^+$ <declarator> <method-body>
+ @[<properties>@]
+ @<declaration-specifier>^+ <declarator> <method-body>
<method-body> ::= "{" <c-fragment> "}" | "extern" ";"
\end{grammar}