X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/5b0a2bdbdeabfd02923a9998e6e2dafa614b47f3..239fa5bd3dff0b38b0cebdd3438311f21c24ba4f:/doc/sod.tex diff --git a/doc/sod.tex b/doc/sod.tex index 50f6121..ba2aaa5 100644 --- a/doc/sod.tex +++ b/doc/sod.tex @@ -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 $[$@$]$ means an optional @: +\item @[@@] means an optional @: \begin{quote} - \syntax{$[$$]$ ::= $\epsilon$ | } + \syntax{@[@] ::= $\epsilon$ | } \end{quote} -\item @$^*$ means a sequence of zero or more @s: +\item @^* means a sequence of zero or more @s: \begin{quote} - \syntax{$^*$ ::= $\epsilon$ | $^*$ } + \syntax{@^* ::= $\epsilon$ | @^* } \end{quote} -\item @$^+$ means a sequence of one or more @s: +\item @^+ means a sequence of one or more @s: \begin{quote} - \syntax{$^+$ ::= $^*$} + \syntax{@^+ ::= @^*} \end{quote} \item @ means a sequence of one or more @s separated by commas: @@ -212,19 +214,19 @@ disambiguate: \subsubsection{Identifiers} \label{sec:syntax.lex.id} \begin{grammar} - ::= $^*$ + ::= @^* - ::= $|$ "_" + ::= | "_" - ::= $|$ + ::= @! - ::= "A" $|$ "B" $|$ \dots\ $|$ "Z" -\alt "a" $|$ "b" $|$ \dots\ $|$ "z" + ::= "A" | "B" | \dots\ | "Z" +\alt "a" | "b" | \dots\ | "z" \alt - ::= "0" $|$ + ::= "0" | - ::= "1" $|$ "2" $| \cdots |$ "9" + ::= "1" | "2" $| \cdots |$ "9" \end{grammar} The precise definition of @ is left to the function @@ -235,10 +237,10 @@ programmers are encouraged to limit themselves to the standard ASCII letters. \begin{grammar} ::= -"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} - ::= "\"" $^*$ "\"" + ::= "\"" @^* "\"" ::= "'" "'" @@ -276,21 +278,21 @@ discouraged. \alt \alt - ::= $^*$ + ::= @^* - ::= "0" $($"b"$|$"B"$)$ $^+$ + ::= "0" @("b"|"B"@) @^+ - ::= "0" $|$ "1" + ::= "0" | "1" - ::= "0" $[$"o"$|$"O"$]$ $^+$ + ::= "0" @["o"|"O"@] @^+ - ::= "0" $|$ "1" $| \cdots |$ "7" + ::= "0" | "1" $| \cdots |$ "7" - ::= "0" $($"x"$|$"X"$)$ $^+$ + ::= "0" @("x"|"X"@) @^+ ::= -\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. ::= "/*" - $^*$ $($$^+$ $^*)^*$ - $^*$ + @^* @(@^+ @^*@)^* + @^* "*/" ::= "*" @@ -324,7 +326,7 @@ alphanumeric. ::= any character other than "*" or "/" - ::= "//" $^*$ + ::= "//" @^* ::= a newline character @@ -371,7 +373,7 @@ brackets, braces or parenthesis ends the fragment. \subsection{Module syntax} \label{sec:syntax-module} \begin{grammar} - ::= $^*$ + ::= @^* ::= \alt @@ -484,12 +486,12 @@ declarations instead. \begin{grammar} ::= - "code" ":" $[$$]$ + "code" ":" @[@] "{" "}" ::= "[" "]" - ::= $^+$ + ::= @^+ \end{grammar} The @ 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 @, and one of the following, up to reordering. \begin{itemize} \item @ -\item @"struct" , @"union" , @"enum" +\item @"struct" @, @"union" @, @"enum" @ \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} ::= - $^*$ $^*$ + @^* @^* ::= | \alt "(" ")" ::= "." - ::= "*" $^*$ + ::= "*" @^* ::= "[" "]" \alt "(" ")" ::= | "..." -\alt $[$"," "..."$]$ +\alt @["," "..."@] - ::= $^+$ + ::= @^+ - ::= | $[$$]$ + ::= | @[@] ::= - $^+$ | $^*$ + @^+ | @^* ::= "(" ")" -\alt $[$$]$ $^+$ +\alt @[@] @^+ \end{grammar} The declarator syntax is taken from C, but with some differences. @@ -680,9 +682,9 @@ class Sub : Super { \begin{grammar} ::= - $[$$]$ + @[@] "class" ":" - "{" $^*$ "}" + "{" @^* "}" ::= ";" \alt @@ -727,10 +729,10 @@ These items are discussed on the following sections. \begin{grammar} ::= - $[$$]$ - $^+$ + @[@] + @^+ - ::= $[$"=" $]$ + ::= @["=" @] \end{grammar} A @ 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} - ::= $[$"class"$]$ + ::= @["class"@] ::= "=" @@ -792,16 +794,16 @@ The initializer has one of two forms. \begin{grammar} ::= - $[$$]$ - $^+$ $[$$]$ + @[@] + @^+ @[@] \end{grammar} \subsubsection{Method items} \label{sec:syntax.class.method} \begin{grammar} ::= - $[$$]$ - $^+$ + @[@] + @^+ ::= "{" "}" | "extern" ";" \end{grammar}