Work in progress. Mostly bug fixing.
[sod] / doc / sod.tex
index 50f6121..ba2aaa5 100644 (file)
@@ -50,6 +50,8 @@
 \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%
@@ -165,17 +167,17 @@ unusual notation in order to make the presentation easier to read.
   \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:
@@ -212,19 +214,19 @@ disambiguate:
 \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
@@ -235,10 +237,10 @@ programmers are encouraged to limit themselves to the standard ASCII letters.
 
 \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
@@ -248,7 +250,7 @@ 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> "'"
 
@@ -276,21 +278,21 @@ discouraged.
 \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
@@ -314,8 +316,8 @@ alphanumeric.
 
 <block-comment> ::=
   "/*"
-  <not-star>$^*$ $($<star>$^+$ <not-star-or-slash> <not-star>$^*)^*$
-  <star>$^*$
+  @<not-star>^* @(@<star>^+ <not-star-or-slash> @<not-star>^*@)^*
+  @<star>^*
   "*/"
 
 <star> ::= "*"
@@ -324,7 +326,7 @@ alphanumeric.
 
 <not-star-or-slash> ::= any character other than "*" or  "/"
 
-<line-comment> ::= "//" <not-newline>$^*$ <newline>
+<line-comment> ::= "//" @<not-newline>^* <newline>
 
 <newline> ::= a newline character
 
@@ -371,7 +373,7 @@ brackets, braces or parenthesis ends the fragment.
 \subsection{Module syntax} \label{sec:syntax-module}
 
 \begin{grammar}
-<module> ::= <definition>$^*$
+<module> ::= @<definition>^*
 
 <definition> ::= <import-definition>
 \alt <load-definition>
@@ -484,12 +486,12 @@ declarations instead.
 
 \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.
@@ -592,7 +594,7 @@ combinations are permitted.  A declaration specifier must consist of zero or
 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"
@@ -610,30 +612,30 @@ All of these have their usual C meanings.
 
 \begin{grammar}
 <declarator> ::=
-  <pointer>$^*$ <inner-declarator> <declarator-suffix>$^*$
+  @<pointer>^* <inner-declarator> @<declarator-suffix>^*
 
 <inner-declarator> ::= <identifier> | <qualified-identifier>
 \alt "(" <declarator> ")"
 
 <qualified-identifier> ::= <identifier> "." <identifier>
 
-<pointer> ::= "*" <qualifier>$^*$
+<pointer> ::= "*" @<qualifier>^*
 
 <declarator-suffix> ::= "[" <c-fragment> "]"
 \alt "(" <arguments> ")"
 
 <arguments> ::= <empty> | "..."
-\alt <argument-list> $[$"," "..."$]$
+\alt <argument-list> @["," "..."@]
 
-<argument> ::= <declaration-specifier>$^+$ <argument-declarator>
+<argument> ::= @<declaration-specifier>^+ <argument-declarator>
 
-<argument-declarator> ::= <declarator> | $[$<abstract-declarator>$]$
+<argument-declarator> ::= <declarator> | @[<abstract-declarator>@]
 
 <abstract-declarator> ::=
-  <pointer>$^+$ | <pointer>$^*$ <inner-abstract-declarator>
+  @<pointer>^+ | @<pointer>^* <inner-abstract-declarator>
 
 <inner-abstract-declarator> ::= "(" <abstract-declarator> ")"
-\alt $[$<inner-abstract-declarator>$]$ <declarator-suffix>$^+$
+\alt @[<inner-abstract-declarator>@] @<declarator-suffix>^+
 \end{grammar}
 
 The declarator syntax is taken from C, but with some differences.
@@ -680,9 +682,9 @@ class Sub : Super {
 
 \begin{grammar}
 <full-class-definition> ::=
-  $[$<properties>$]$
+  @[<properties>@]
   "class" <identifier> ":" <identifier-list>
-  "{" <class-item>$^*$ "}"
+  "{" @<class-item>^* "}"
 
 <class-item> ::= <slot-item> ";"
 \alt <message-item>
@@ -727,10 +729,10 @@ These items are discussed on the following sections.
 
 \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
@@ -763,7 +765,7 @@ class Example : Super {
 \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>
 
@@ -792,16 +794,16 @@ The initializer has one of two forms.
 
 \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}