| 1 |
% -*- Mode:LaTeX -*- |
| 2 |
% CafeOBJ 1.5.X syntax reference card. |
| 3 |
% comment out the following 2 lines if you use old latex209 |
| 4 |
% \documentclass[a4paper]{article} |
| 5 |
\documentclass[a4paper]{article} |
| 6 |
\usepackage[scale=0.76]{geometry} |
| 7 |
% \usepackage[dvipdfm]{hyperref} |
| 8 |
\usepackage{hyperref} |
| 9 |
%%%% box |
| 10 |
\usepackage{fancybox} |
| 11 |
\newenvironment{fminipage}% |
| 12 |
{\begin{Sbox}\begin{minipage}}% |
| 13 |
{\end{minipage}\end{Sbox}\fbox{\TheSbox}} |
| 14 |
\newcommand{\vsep}{\vskip\fboxsep} |
| 15 |
\newcommand{\nvsep}{\vskip\fboxsep\noindent} |
| 16 |
%%%%% xlatex specific |
| 17 |
\usepackage{fontspec,xltxtra,xunicode} |
| 18 |
\defaultfontfeatures{Mapping=tex-text} |
| 19 |
\setromanfont[Mapping=tex-text]{Times New Roman} |
| 20 |
\setsansfont[Scale=MatchLowercase,Mapping=tex-text]{Gill Sans} |
| 21 |
\setmonofont[Scale=MatchLowercase]{Andale Mono} |
| 22 |
%** begin header |
| 23 |
\makeatletter |
| 24 |
\def\cafeobj{\textsf{CafeOBJ}} |
| 25 |
% kbd - argument is characters typed literally. |
| 26 |
\def\kbd#1{{\texttt{#1}\null}} |
| 27 |
% beginexample...endexample - surrounds literal text, such a code example. |
| 28 |
% typeset in a typewriter font with line breaks preserved. |
| 29 |
\def\example{\leavevmode\begingroup |
| 30 |
\obeylines\obeyspaces\parskip0pt\texttt} |
| 31 |
{\obeyspaces\global\let =\ } |
| 32 |
\def\endexample{\endgroup} |
| 33 |
% terminal - used for terminal symbols, argument is characters appear in sf. |
| 34 |
\def\sym#1{\textsf{#1}\null} |
| 35 |
% nonterm - used for non terminal symbols, argument is characters typed with |
| 36 |
% italic face. |
| 37 |
\def\nonterm#1{\textit{#1}\null} |
| 38 |
% syntax ... endsyntax |
| 39 |
\def\xstrut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi} |
| 40 |
\def\syntax{\syntaxoutnonbox\halign\bgroup |
| 41 |
\xstrut$\@lign##$\hfil &\hfil$\@lign{}##{}$\hfil |
| 42 |
&$\@lign##$\hfil &\qquad\@lign-- ##\hfil\cr} |
| 43 |
\def\endsyntax{\crcr\egroup$$ |
| 44 |
\global\@ignoretrue |
| 45 |
} |
| 46 |
\def\syntaxoutnonbox{\xleavevmode$$ |
| 47 |
\parskip=0pt\lineskip=0pt |
| 48 |
\def\\{\crcr}% Must have \def and not \let for nested alignments. |
| 49 |
\everycr={\noalign{\penalty10000}} |
| 50 |
\tabskip=0pt} |
| 51 |
\def\xleavevmode{\ifvmode\if@inlabel\indent\else\if@noskipsec\indent\else |
| 52 |
\if@nobreak\global\@nobreakfalse\everypar={}\fi |
| 53 |
{\parskip=0pt\noindent}\fi\fi\fi} |
| 54 |
\def\@but{\noalign{\nointerlineskip}} |
| 55 |
\def\alt{{\;|\;}} |
| 56 |
\def\seqof#1{\mbox{\textbf{\{}}\;{#1}\;\mbox{\textbf{\}}}} |
| 57 |
\def\optn#1{\textbf{[}\;{#1}\;\textbf{]}} |
| 58 |
\def\synindent{\;\;\;} |
| 59 |
\makeatother |
| 60 |
%** end of header |
| 61 |
|
| 62 |
\title{\cafeobj\ Syntax Quick Reference \\ |
| 63 |
{\small for Interpreter version 1.5.0 or later}} |
| 64 |
\date{\today} |
| 65 |
%\author{} |
| 66 |
\author{Toshimi Sawada\thanks{\texttt{[email protected]}} |
| 67 |
} |
| 68 |
\begin{document} |
| 69 |
\maketitle |
| 70 |
\tableofcontents |
| 71 |
% |
| 72 |
\setlength{\parindent}{0pt} |
| 73 |
\setlength{\parskip}{1.4ex} |
| 74 |
\section{Syntax} |
| 75 |
\label{sec:cafeobj-syntax} |
| 76 |
|
| 77 |
We use an extended BNF grammar to define the syntax. The general form |
| 78 |
of a production is |
| 79 |
\begin{syntax} |
| 80 |
\synindent\synindent nonterminal &::=& alternative \alt alternative \alt \cdots \alt alternative |
| 81 |
\end{syntax} |
| 82 |
|
| 83 |
The following extensions are used: |
| 84 |
\begin{center} |
| 85 |
\begin{fminipage}{0.7\textwidth} |
| 86 |
\begin{tabular}{ll} |
| 87 |
a $\cdots$ & a list of one or more \textit{a}s. \\ |
| 88 |
a, $\cdots$ & a list of one or more \textit{a}s separated by commas: \\ |
| 89 |
& ``a'' or ``a, a'' or ``a, a, a'', etc. \\ |
| 90 |
$\seqof{\textrm{a}}$ & \textbf{\{} and \textbf{\}} are meta-syntactical |
| 91 |
brackets \\ |
| 92 |
& treating \textit{a} as one syntactic category. \\ |
| 93 |
$\optn{\textrm{a}}$ & an optional \textit{a}: `` '' or ``a''. |
| 94 |
\end{tabular} |
| 95 |
\end{fminipage} |
| 96 |
\end{center} |
| 97 |
Nonterminal symbols appear in \textit{italic face}. Terminal symbols |
| 98 |
appear in the face like this: ``\sym{terminal}'', and may be |
| 99 |
surrounded by `` and '' for emphasis or to avoid confusion |
| 100 |
with meta characters used in the extended BNF. We will refer terminal |
| 101 |
symbols other than self-terminating characters (see section |
| 102 |
~\ref{sec:selfterminating}) as \textit{keyword}s in this document. |
| 103 |
|
| 104 |
%\subsection{CafeOBJ program} |
| 105 |
\subsection{CafeOBJ Spec} |
| 106 |
\label{sec:cafeobjprogram} |
| 107 |
\begin{syntax} |
| 108 |
\synindent\synindent spec &::=& \seqof{module \alt view \alt eval} \cdots |
| 109 |
\end{syntax} |
| 110 |
A \cafeobj\ spec is a sequence of \nonterm{module} (module declaration |
| 111 |
-- section ~\ref{sec:module-decl}), \nonterm{view} (view declaration -- |
| 112 |
section ~\ref{sec:view-decl}) or \nonterm{eval} (\textit{reduce} or |
| 113 |
\textit{execute} term -- section ~\ref{sec:eval}). |
| 114 |
|
| 115 |
\subsection{Module Declaration} |
| 116 |
\label{sec:module-decl} |
| 117 |
\begin{syntax} |
| 118 |
module &::=& module\_type\; module\_name \; |
| 119 |
\optn{parameters} \; |
| 120 |
\optn{principal\_sort} \\ |
| 121 |
&& \sym{``\{''}\; module\_elt\cdots \; \sym{``\}''} \\ |
| 122 |
\synindent module\_type &::=& \sym{module} \alt \sym{module!} \alt |
| 123 |
\sym{module*}\\ |
| 124 |
\synindent module\_name &::=& ident & |
| 125 |
\footnote{The nonterminal \textit{ident} is for identifiers and |
| 126 |
will be defined in the section ~\ref{sec:identifier}.} \\ |
| 127 |
parameters &::=& \sym{``(''}\; parameter, \cdots \sym{``)''}\\ |
| 128 |
\synindent parameter &::=& |
| 129 |
\optn{\sym{protecting}\alt\sym{extending}\alt\sym{including}}\; |
| 130 |
paramter\_name \; |
| 131 |
\sym{::}\; module\_expr &\footnote{\textit{module\_expr} is defined in |
| 132 |
the section ~\ref{sec:modexpr}.}\footnote{If optional |
| 133 |
$\optn{\sym{protecting}\alt\sym{extending}\alt\sym{including}}$ is omitted, it is |
| 134 |
defaulted to \sym{protecting}.} |
| 135 |
\\ |
| 136 |
\synindent parameter\_name &::=& ident \\ |
| 137 |
principal\_sort &::=& \sym{principal-sort}\; sort\_name \\ |
| 138 |
% module\_elt &::=& import \alt sort \alt record \alt operator \alt |
| 139 |
module\_elt &::=& import \alt sort \alt operator \alt |
| 140 |
variable \alt axiom \alt macro \alt comment &\footnote{\nonterm{comment} is |
| 141 |
descussed in section ~\ref{sec:comments}.}\\ |
| 142 |
import &::=& \seqof{\sym{protecting}\alt\sym{extending}\alt\sym{including}\alt\sym{using}} |
| 143 |
\sym{``(''}\;module\_expr\;\sym{``)''}\\ |
| 144 |
sort & ::= & visible\_sort \alt hidden\_sort \\ |
| 145 |
\synindent visible\_sort & ::=& \sym{``[''}\; sort\_decl, \cdots \; \sym{``]''} \\ |
| 146 |
\synindent hidden\_sort & ::=& \sym{``*[''}\; sort\_decl, \cdots \; \sym{``]*''} \\ |
| 147 |
\synindent sort\_decl &::=& sort\_name\; \cdots\; \optn{supersorts\; \cdots} \\ |
| 148 |
\synindent supersorts &::=& <\; sort\_name\; \cdots \\ |
| 149 |
\synindent sort\_name &::=& sort\_symbol\optn{qualifier} |
| 150 |
&\footnote{There must not be any separators (see section |
| 151 |
~\ref{sec:lex}) between \nonterm{ident} and \nonterm{qualifier}.} |
| 152 |
\\ |
| 153 |
\synindent sort\_symbol &::=& ident \\ |
| 154 |
\synindent qualifier &::=& \sym{``.''}module\_name\\ |
| 155 |
% record &::=& \sym{record}\; sort\_name\; \optn{super\;\cdots}\; |
| 156 |
% \sym{``\{''}\; \seqof{slot \alt comment}\cdots \; \sym{``\}''} \\ |
| 157 |
% \synindent super &::=& |
| 158 |
% \sym{``[''}\;sort\_name\;\optn{\sym{``(''}\; slot\_rename,\cdots |
| 159 |
% \sym{``)''}}\;\sym{``]''} \\ |
| 160 |
% \synindent slot &::=& slot\_name : sort\_name \alt |
| 161 |
% slot\_name\;\sym{=}\;\sym{``(''}term\sym{``)''}\;:\; sort\_name \\ |
| 162 |
% \synindent slot\_name &::=& ident \\ |
| 163 |
% \synindent slot\_rename &::=& slot\_name\; \verb|->|\; slot\_name\\ |
| 164 |
operator &::=& \seqof{\sym{op}\alt\sym{bop}} |
| 165 |
\; operator\_symbol\; : \; \optn{arity}\; \verb|->|\; |
| 166 |
coarity \; \optn{op\_attrs} |
| 167 |
&\footnote{\nonterm{operator\_symbol} is defined in section |
| 168 |
~\ref{sec:opsymbol}.}\\ |
| 169 |
\synindent arity &::=& sort\_name \cdots \\ |
| 170 |
\synindent coarity &::=& sort\_name \\ |
| 171 |
\synindent op\_attrs &::=& \sym{``\{''}\;op\_attr\cdots\;\sym{``\}''} \\ |
| 172 |
\synindent op\_attr &::=& \sym{constr} \alt |
| 173 |
\sym{associative} \alt \sym{commutative} |
| 174 |
\alt\sym{idempotent} |
| 175 |
\alt \seqof{\sym{id:} \alt \sym{idr:}} \sym{``(''} \; term\; \sym{``)''} |
| 176 |
%&\footnote{The general syntax of \nonterm{term} is defined in section |
| 177 |
% ~\ref{sec:term}.} |
| 178 |
\\ |
| 179 |
&\alt & \sym{strat: ``(''}\; natural \cdots\; \sym{``)''} |
| 180 |
\alt\sym{prec:}\; natural |
| 181 |
\alt \sym{l-assoc} \alt \sym{r-assoc} \alt \sym{coherent} \alt \sym{demod} |
| 182 |
&\footnote{\nonterm{natural} is a natural number written in ordinal |
| 183 |
arabic notation.} \\ |
| 184 |
variable &::=& \sym{var}\; var\_name\; :\; sort\_name \alt |
| 185 |
\sym{vars} \; var\_name\cdots\; :\; sort\_name \\ |
| 186 |
\synindent var\_name &::=& ident \\ |
| 187 |
axiom &::=& equation \alt cequation\alt transition \alt ctransition \alt fol\\ |
| 188 |
\synindent equation &::=& \seqof{\sym{eq} \alt \sym{beq}}\; |
| 189 |
\optn{label}\; term \; \sym{=} \; term\; \sym{``.''}\\ |
| 190 |
\synindent cequation &::=& \seqof{\sym{ceq} \alt \sym{bceq}}\; |
| 191 |
\optn{label}\; term \; \sym{=} |
| 192 |
\; term\; \sym{if}\; term\;\sym{``.''} \\ |
| 193 |
\synindent transition &::=& \seqof{\sym{trans} \alt \sym{btrans}}\; |
| 194 |
\optn{label}\; term \; \verb|=>| \; term \;\sym{``.''}\\ |
| 195 |
\synindent ctransition &::=& \seqof{\sym{ctrans} \alt \sym{bctrans}}\; |
| 196 |
\optn{label}\; term \; \verb|=>| \; term\; \sym{if}\; term\;\sym{``.''}\\ |
| 197 |
\synindent fol & ::= & \sym{ax} \optn{label}\; term \; \sym{``.''}\\ |
| 198 |
\synindent label &::=& \sym{``[''}\; ident\cdots\; \sym{``]:''}\\ |
| 199 |
macro &::=& \sym{\#define}\; term\; \sym{::=}\; term\; \sym{``.''} |
| 200 |
\end{syntax} |
| 201 |
|
| 202 |
\subsection{Module Expression} |
| 203 |
\label{sec:modexpr} |
| 204 |
\begin{syntax} |
| 205 |
module\_expr &::=& module\_name \alt sum \alt rename \alt instantiation |
| 206 |
\alt \sym{``(''} module\_expr \sym{``)''} \\ |
| 207 |
sum &::=& module\_expr\; \seqof{+\;\; module\_expr} \cdots \\ |
| 208 |
rename &::=& module\_expr\;\sym{*}\;\sym{``\{''} rename\_map,\cdots |
| 209 |
\sym{``\}''} \\ |
| 210 |
% instantiation &::=& module\_expr\;\sym{``(''} |
| 211 |
% \seqof{ident \optn{qualifier}\;\verb|<=|\;aview},\cdots |
| 212 |
% \sym{``)''} |
| 213 |
instantiation &::=& module\_expr\;\sym{``(''}\textbf{\{}\;ident |
| 214 |
[ qualifier ]\; \verb|<=|\; aview\textbf{\}},\;\cdots\;\sym{``)''} |
| 215 |
\\ |
| 216 |
rename\_map &::=& sort\_map \alt op\_map \\ |
| 217 |
sort\_map &::=& \seqof{\sym{sort} \alt \sym{hsort}}\; |
| 218 |
sort\_name \; \verb|->|\; ident \\ |
| 219 |
op\_map &::=& \seqof{\sym{op} \alt \sym{bop}}\; |
| 220 |
op\_name\;\verb|->|\;operaotr\_symbol \\ |
| 221 |
op\_name &::=& operator\_symbol\alt |
| 222 |
\sym{``(''}operator\_symbol\sym{``)''}qualifier\\ |
| 223 |
aview &::=& view\_name\alt module\_expr\\ |
| 224 |
& \alt & |
| 225 |
\sym{view to}\; module\_expr\;\sym{``\{''} view\_elt,\cdots \sym{``\}''} \\ |
| 226 |
view\_name &::=& ident \\ |
| 227 |
view\_elt &::=& sort\_map \alt op\_view \alt variable \\ |
| 228 |
op\_view &::=& op\_map \alt term\; \verb|->|\; term |
| 229 |
\end{syntax} |
| 230 |
|
| 231 |
When a module expression is not fully parenthesized, the proper |
| 232 |
nesting of subexpressions may be ambiguous. The following precedence rule |
| 233 |
is used to resolve such ambiguity: |
| 234 |
\[ \nonterm{sum} < \nonterm{rename} < \nonterm{instantiation} \] |
| 235 |
|
| 236 |
\subsection{View Declaration} |
| 237 |
\label{sec:view-decl} |
| 238 |
\begin{syntax} |
| 239 |
view &::=& \sym{view}\; view\_name\; \sym{from}\; module\_expr\; \sym{to} |
| 240 |
\; module\_expr \\ |
| 241 |
&& \sym{``\{''}\; view\_elt, \cdots \; \sym{``\}''} \\ |
| 242 |
\end{syntax} |
| 243 |
|
| 244 |
%\subsection{Term} |
| 245 |
%\label{sec:term} |
| 246 |
|
| 247 |
\subsection{Evaluation} |
| 248 |
\label{sec:eval} |
| 249 |
\begin{syntax} |
| 250 |
eval & ::= & \seqof{\sym{reduce}\alt\sym{behavioural-reduce} |
| 251 |
\alt\sym{execute}}\; context\; |
| 252 |
term\; \sym{``.''} \\ |
| 253 |
context & ::=& \sym{in}\; module\_expr\;\sym{:} |
| 254 |
\end{syntax} |
| 255 |
The interpreter has a notion of \textit{current module} which |
| 256 |
is specified by a \nonterm{module\_expr} and establishes a context. |
| 257 |
If it is set, \nonterm{context} can be omitted. |
| 258 |
|
| 259 |
\subsection{Sugars and Abbriviations} |
| 260 |
\label{sec:sugar} |
| 261 |
\paragraph{Module type} |
| 262 |
There are following abbreviations for \nonterm{module\_type}. |
| 263 |
\begin{center} |
| 264 |
\begin{tabular}{ll}\hline |
| 265 |
Keyword & Abbriviation \\\hline |
| 266 |
\sym{module} & \sym{mod}\\ |
| 267 |
\sym{module!} & \sym{mod!} \\ |
| 268 |
\sym{module*} & \sym{mod*}\\\hline |
| 269 |
\end{tabular} |
| 270 |
\end{center} |
| 271 |
|
| 272 |
\paragraph{Module Declaration} |
| 273 |
\begin{syntax} |
| 274 |
make &::=& \sym{make}\;module\_name\;\sym{``(''}\; module\_expr\;\sym{``)''} |
| 275 |
\end{syntax} |
| 276 |
\nonterm{make} is a short hand for declaring module of |
| 277 |
name \nonterm{module\_name} which imports \nonterm{module\_expr} with |
| 278 |
protecting mode. |
| 279 |
\begin{example} |
| 280 |
make FOO (BAR * \{sort Bar -> Foo\}) |
| 281 |
\end{example} |
| 282 |
is equivalent to |
| 283 |
\begin{example} |
| 284 |
module FOO \{ protecting (BAR * \{sort Bar -> Foo\}) \} |
| 285 |
\end{example} |
| 286 |
|
| 287 |
\paragraph{Principal Sort} |
| 288 |
\sym{principal-sort} can be abbriviated to \sym{psort}. |
| 289 |
|
| 290 |
\paragraph{Import Mode} |
| 291 |
For import modes, the following abbriviations can be used: |
| 292 |
\begin{center} |
| 293 |
\begin{tabular}{ll}\hline |
| 294 |
Keyword & Abbriviation \\\hline |
| 295 |
\sym{protecting} & \sym{pr} \\ |
| 296 |
\sym{extending} & \sym{ex} \\ |
| 297 |
\sym{including} & \sym{inc} \\ |
| 298 |
\sym{using} & \sym{us} \\\hline |
| 299 |
\end{tabular} |
| 300 |
\end{center} |
| 301 |
|
| 302 |
\paragraph{Simultaneous Operator Declaration} |
| 303 |
Several operators with the same arity, coarity and operator attributes |
| 304 |
can be declared at once by \sym{ops}. |
| 305 |
The form |
| 306 |
\begin{syntax} |
| 307 |
\sym{ops}\; operator\_symbol_1 \cdots operator\_symbol_n\; |
| 308 |
:\; arity\; \verb|->|\; coarity\; op\_attrs |
| 309 |
\end{syntax} |
| 310 |
is just equivalent to the following multiple operator declarations: |
| 311 |
\begin{syntax} |
| 312 |
\sym{op}\; & operator\_symbol_1\;:\;arity\;\verb|->|\;coarity\;op\_attrs |
| 313 |
\\ |
| 314 |
&\vdots\\ |
| 315 |
\sym{op}\; & operator\_symbol_n\;:\;arity\;\verb|->|\;coarity\;op\_attrs |
| 316 |
\end{syntax} |
| 317 |
|
| 318 |
\sym{bops} is the counterpart of \sym{ops} for behavioural operators. |
| 319 |
\begin{syntax} |
| 320 |
\sym{bops}\; operator\_symbol\;\cdots\; : \; arity\;\verb|->|\; |
| 321 |
coarity \; op\_attrs |
| 322 |
\end{syntax} |
| 323 |
|
| 324 |
In simultaneous declarations, parentheses are sometimes necessary |
| 325 |
to separate operator symbols. This is always required if an operator |
| 326 |
symbol contains dots, blank characters or underscores. |
| 327 |
|
| 328 |
\paragraph{Predicate} |
| 329 |
Predicate declaration (\nonterm{predicate}) is a syntactic sugar for |
| 330 |
declaring \sym{Bool} valued operators, and has the syntax: |
| 331 |
\begin{syntax} |
| 332 |
predicate &::=& |
| 333 |
\sym{pred}\;operator\_symbol\;:\;arity\;\optn{op\_attrs} |
| 334 |
&\footnote{You cannot use \nonterm{sort\_name} of the same |
| 335 |
character sequence as that of any keywords, i.e., \sym{module}, |
| 336 |
\sym{op}, \sym{vars}, etc. in \nonterm{arity}.} |
| 337 |
\end{syntax} |
| 338 |
The form |
| 339 |
\begin{syntax} |
| 340 |
\sym{pred}\;operator\_symbol\;:\;arity\;op\_attrs |
| 341 |
\end{syntax} |
| 342 |
is equivalent to: |
| 343 |
\begin{syntax} |
| 344 |
\sym{op}\;operator\_symbol\;:\;arity\;\verb|->|\; \sym{Bool} \;op\_attrs |
| 345 |
\end{syntax} |
| 346 |
|
| 347 |
\paragraph{Operator Attributes} |
| 348 |
The following abbriviations are available: |
| 349 |
\begin{center} |
| 350 |
\begin{tabular}{ll}\hline |
| 351 |
Keyword & Abbriviation \\\hline |
| 352 |
\sym{associative} & \sym{assoc} \\ |
| 353 |
\sym{commutative} & \sym{comm} \\ |
| 354 |
\sym{idempotent} & \sym{idem} \\\hline |
| 355 |
\end{tabular} |
| 356 |
\end{center} |
| 357 |
|
| 358 |
\paragraph{Axioms} |
| 359 |
For the keywords introducing axioms, the following |
| 360 |
abbriviations can be used: |
| 361 |
\begin{center} |
| 362 |
\begin{tabular}{ll|ll}\hline |
| 363 |
Keyword & Abbriviation & Keyword & Abbriviation \\\hline |
| 364 |
\sym{ceq} & \sym{cq} & |
| 365 |
\sym{bceq} & \sym{bcq} \\ |
| 366 |
\sym{trans} & \sym{trns} & |
| 367 |
\sym{ctrans} & \sym{ctrns} \\ |
| 368 |
\sym{btrans} & \sym{btrns} & |
| 369 |
\sym{bctrans} & \sym{bctrns} \\\hline |
| 370 |
\end{tabular} |
| 371 |
\end{center} |
| 372 |
|
| 373 |
\paragraph{Blocks of Declarations} |
| 374 |
References to (importations of) other modules, signature definitions and |
| 375 |
axioms can be clusterd in blocked declarations: |
| 376 |
\begin{syntax} |
| 377 |
imports &::=& |
| 378 |
\sym{imports}\;\sym{``\{''}\\ |
| 379 |
&&\synindent\seqof{import \alt comment}\cdots\\ |
| 380 |
&&\sym{``\}''}\\ |
| 381 |
signature &::=& \sym{signature}\;\sym{``\{''}\\ |
| 382 |
&&\synindent\seqof{sort \alt record \alt operator \alt |
| 383 |
comment}\cdots\\ |
| 384 |
&&\sym{``\}''}\\ |
| 385 |
axioms &::=& \sym{axioms}\;\sym{``\{''}\\ |
| 386 |
&&\synindent\seqof{variable \alt axiom\alt comment}\cdots\\ |
| 387 |
&&\sym{``\}''} |
| 388 |
\end{syntax} |
| 389 |
|
| 390 |
\paragraph{Views} |
| 391 |
To reduce the complexity of views appearing in module instantiation, |
| 392 |
some sugars are provided. |
| 393 |
|
| 394 |
First, it is possible to identify parameters by positions, not by names. |
| 395 |
For example, if a parameterized module is declared like |
| 396 |
\begin{example} |
| 397 |
\sym{module!} FOO (A1 :: TH1, A2 :: TH2) \sym{\{} ... \sym{\}} |
| 398 |
\end{example} |
| 399 |
the form |
| 400 |
\begin{example} |
| 401 |
FOO(V1, V2) |
| 402 |
\end{example} |
| 403 |
is equivalent to |
| 404 |
\begin{example} |
| 405 |
FOO(A1 <= V1, A2 <= V2) |
| 406 |
\end{example} |
| 407 |
|
| 408 |
Secondly, \sym{view to} construct in arguments of module |
| 409 |
instantiations can always be omitted. That is, |
| 410 |
\begin{example} |
| 411 |
FOO(A1 <= \sym{view to} \nonterm{module\_expr}\{...\}) |
| 412 |
\end{example} |
| 413 |
can be written as |
| 414 |
\begin{example} |
| 415 |
FOO(A1 <= \nonterm{module\_expr}\{...\}) |
| 416 |
\end{example} |
| 417 |
|
| 418 |
\paragraph{Evaluation} |
| 419 |
\begin{center} |
| 420 |
\begin{tabular}{ll}\hline |
| 421 |
Keyword & Abbriviation \\\hline |
| 422 |
\sym{reduce} & \sym{red} \\ |
| 423 |
\sym{bereduce} & \sym{bred} \\ |
| 424 |
\sym{execute} & \sym{exec} \\\hline |
| 425 |
\end{tabular} |
| 426 |
\end{center} |
| 427 |
|
| 428 |
\section{Lexical Considerations} |
| 429 |
\label{sec:lex} |
| 430 |
A \cafeobj\ spec is written as a sequence of tokens and separators. |
| 431 |
A \textit{token} is a sequence of ``printing'' ASCII characters (octal |
| 432 |
40 through 176).\footnote{The current interpreter accepts Unicode characters also, but this is beyond the definition of |
| 433 |
CafeOBJ language.} |
| 434 |
A \textit{separator} is a ``blank'' character (space, vertical |
| 435 |
tab, horizontal tab, carriage return, newline, form feed). |
| 436 |
In general, any mumber of separators may appear between tokens. |
| 437 |
|
| 438 |
\subsection{Reserved Word} |
| 439 |
\label{sec:keywords} |
| 440 |
There are \textit{no\/} reserved word in \cafeobj. |
| 441 |
One can use keywords such as \sym{module}, \sym{op}, \sym{var}, |
| 442 |
or \sym{signature}, etc. for identifiers or operator symbols. |
| 443 |
|
| 444 |
\subsection{Self-terminating Characters} |
| 445 |
\label{sec:selfterminating} |
| 446 |
The following eight characters are always treated as \textit{self-terminating}, |
| 447 |
i.e., the character itself construct a token. |
| 448 |
\begin{center} |
| 449 |
\begin{tabular}{llllllll} |
| 450 |
\sym{(} & \sym{)} & \sym{,} & \sym{[} & \sym{]} |
| 451 |
& \sym{\{} & \sym{\}} & \sym{;} |
| 452 |
\end{tabular} |
| 453 |
\end{center} |
| 454 |
|
| 455 |
\subsection{Identifier} |
| 456 |
\label{sec:identifier} |
| 457 |
Nonterminal \nonterm{ident} is for \emph{identifier} |
| 458 |
which is a sequnce of any printing ASCII characters except |
| 459 |
the followings: |
| 460 |
\begin{center} |
| 461 |
\begin{tabular}{l} |
| 462 |
self-terminating characters (see section ~\ref{sec:selfterminating})\\ |
| 463 |
\sym{.} (dot)\\ |
| 464 |
\sym{"} (double quote)\\ |
| 465 |
\end{tabular} |
| 466 |
\end{center} |
| 467 |
Upper- and lowercase are distinguished in identifiers. |
| 468 |
\nonterm{ident}s are used for module names (\nonterm{module\_name}), |
| 469 |
view names (\nonterm{view\_name}), |
| 470 |
parameter names (\nonterm{parameter\_name}), |
| 471 |
sort symbols (\nonterm{sort\_symbol}), variables(\nonterm{var\_name}), |
| 472 |
slot names (\nonterm{slot\_name}) and labels (\nonterm{label}). |
| 473 |
|
| 474 |
\subsection{Operator Symbol} |
| 475 |
\label{sec:opsymbol} |
| 476 |
The nonterminal \nonterm{operator\_symbol} is used for naming operators |
| 477 |
(\nonterm{operator}) and is a sequence of any ASCII characters |
| 478 |
(self-terminating characters or non-printing characters can be an |
| 479 |
element of operator names.)\footnote{The current implementation does |
| 480 |
not allow EOT character (control-D) to be an element of operator |
| 481 |
symbol. } |
| 482 |
|
| 483 |
Underscores are specially treated when they apper as a part of |
| 484 |
operator names; they reserve the places where arguments of the |
| 485 |
operator are inserted. Thus the single underscore cannot be a |
| 486 |
name of an operator. |
| 487 |
|
| 488 |
\subsection{Comments and Separators} |
| 489 |
\label{sec:comments} |
| 490 |
A \nonterm{comment} is a sequence of characters that begins with one |
| 491 |
of the following four character sequences |
| 492 |
\begin{center} |
| 493 |
\begin{tabular}{ll} |
| 494 |
\verb|--| & |
| 495 |
\verb|-->|\\ |
| 496 |
\verb|**| & |
| 497 |
\verb|**>| \\ |
| 498 |
\end{tabular} |
| 499 |
\end{center} |
| 500 |
which ends with a newline character, and contains only printing ASCII |
| 501 |
characters and horizontal tabs in between. |
| 502 |
|
| 503 |
A \nonterm{separator} is a blank character (space, vertical tab, |
| 504 |
horizontal tab, carriage return, newline, from feed). |
| 505 |
One or more separators must appear between any two adjuacent |
| 506 |
non-self-terminating tokens.\footnote{The same rule is applied to |
| 507 |
\nonterm{term}. |
| 508 |
Further, if an \nonterm{operator\_symbol} contains blanks or |
| 509 |
self-terminating characters, it is sometimes neccessary to enclose a |
| 510 |
term with such operator as top by parentheses for disambiguation.} |
| 511 |
|
| 512 |
Comments also act as separators, but their apperance is limited to |
| 513 |
some specific places (see section ~\ref{sec:cafeobj-syntax}). |
| 514 |
|
| 515 |
\paragraph{Multiline comments} |
| 516 |
A multiple lines which starts with \verb+#|+ and ends with \verb+|#+ |
| 517 |
is treated as multiline comment. |
| 518 |
\begin{center} |
| 519 |
\begin{verbatim} |
| 520 |
#|--------------------------------------------------- |
| 521 |
This is an example of multiline comment. |
| 522 |
Multiline comments are used for large text descriptions of |
| 523 |
code or to comment out chunks of code while developping |
| 524 |
your specification. |
| 525 |
Multiline comments are ignored by the system. |
| 526 |
---------------------------------------------------|# |
| 527 |
\end{verbatim} |
| 528 |
\end{center} |
| 529 |
|
| 530 |
|
| 531 |
\end{document} |
| 532 |
|
| 533 |
% Local variables: |
| 534 |
% compile-command: "latex qref" |
| 535 |
% TeX-master: t |
| 536 |
% End: |