| 
7050
 | 
     1  | 
  | 
| 
 | 
     2  | 
%FIXME
  | 
| 
 | 
     3  | 
% - examples (!?)
  | 
| 
 | 
     4  | 
  | 
| 
7046
 | 
     5  | 
  | 
| 
 | 
     6  | 
\chapter{Isar document syntax}
 | 
| 
 | 
     7  | 
  | 
| 
7134
 | 
     8  | 
FIXME shortcut
  | 
| 
 | 
     9  | 
  | 
| 
7050
 | 
    10  | 
FIXME important note: inner versus outer syntax
  | 
| 
7046
 | 
    11  | 
  | 
| 
 | 
    12  | 
\section{Lexical matters}
 | 
| 
 | 
    13  | 
  | 
| 
 | 
    14  | 
\section{Common syntax entities}
 | 
| 
 | 
    15  | 
  | 
| 
7050
 | 
    16  | 
The Isar proof and theory language syntax has been carefully designed with
  | 
| 
7134
 | 
    17  | 
orthogonality in mind.  Subsequently, we introduce several basic syntactic
  | 
| 
 | 
    18  | 
entities, such as names, terms, theorem specifications, which have been
  | 
| 
 | 
    19  | 
factored out of the actual Isar language elements described later.
  | 
| 
 | 
    20  | 
  | 
| 
7167
 | 
    21  | 
Note that some of the basic syntactic entities introduced below act much like
  | 
| 
 | 
    22  | 
tokens rather than nonterminals, in particular for the sake of error messages.
  | 
| 
7134
 | 
    23  | 
E.g.\ syntax elements such as $\CONSTS$ referring to \railqtoken{name} or
 | 
| 
7167
 | 
    24  | 
\railqtoken{type} would really report a missing name or type rather than any
 | 
| 
 | 
    25  | 
of the constituent primitive tokens such as \railtoken{ident} or
 | 
| 
 | 
    26  | 
\railtoken{string}.
 | 
| 
7046
 | 
    27  | 
  | 
| 
7050
 | 
    28  | 
  | 
| 
 | 
    29  | 
\subsection{Names}
 | 
| 
 | 
    30  | 
  | 
| 
7134
 | 
    31  | 
Entity \railqtoken{name} usually refers to any name of types, constants,
 | 
| 
7167
 | 
    32  | 
theorems etc.\ that are to be \emph{declared} or \emph{defined} (so qualified
 | 
| 
7134
 | 
    33  | 
identifiers are excluded).  Quoted strings provide an escape for
  | 
| 
 | 
    34  | 
non-identifier names or those ruled out by outer syntax keywords (e.g.\ 
  | 
| 
 | 
    35  | 
\verb|"let"|).  Already existing objects are usually referenced by
  | 
| 
 | 
    36  | 
\railqtoken{nameref}.
 | 
| 
7050
 | 
    37  | 
  | 
| 
7141
 | 
    38  | 
\indexoutertoken{name}\indexoutertoken{parname}\indexoutertoken{nameref}
 | 
| 
7046
 | 
    39  | 
\begin{rail}
 | 
| 
7167
 | 
    40  | 
  name: ident | symident | string
  | 
| 
7046
 | 
    41  | 
  ;
  | 
| 
7167
 | 
    42  | 
  parname: '(' name ')'
 | 
| 
7141
 | 
    43  | 
  ;
  | 
| 
7167
 | 
    44  | 
  nameref: name | longident
  | 
| 
7046
 | 
    45  | 
  ;
  | 
| 
 | 
    46  | 
\end{rail}
 | 
| 
 | 
    47  | 
  | 
| 
7050
 | 
    48  | 
  | 
| 
7046
 | 
    49  | 
\subsection{Comments}
 | 
| 
 | 
    50  | 
  | 
| 
7167
 | 
    51  | 
Large chunks of plain \railqtoken{text} are usually given
 | 
| 
 | 
    52  | 
\railtoken{verbatim}, i.e.\ enclosed in \verb|{*|\dots\verb|*}|.  For
 | 
| 
7175
 | 
    53  | 
convenience, any of the smaller text units conforming to \railqtoken{nameref}
 | 
| 
 | 
    54  | 
are admitted as well.  Almost any of the Isar commands may be annotated by
  | 
| 
 | 
    55  | 
some marginal \railnonterm{comment} of the form \texttt{--} \railqtoken{text}.
 | 
| 
7167
 | 
    56  | 
Note that this kind of comment is actually part of the language, while source
  | 
| 
 | 
    57  | 
level comments \verb|(*|\dots\verb|*)| are already stripped at the lexical
  | 
| 
 | 
    58  | 
level.  A few commands such as $\PROOFNAME$ admit additional markup with a
  | 
| 
 | 
    59  | 
``level of interest'': \texttt{\%} followed by an optional number $n$ (default
 | 
| 
 | 
    60  | 
$n = 1$) indicates that the respective part of the document becomes $n$ levels
  | 
| 
 | 
    61  | 
more boring or obscure; \texttt{\%\%} means that the interest drops by
 | 
| 
 | 
    62  | 
$\infty$ --- abandon every hope, who enter here.
  | 
| 
7050
 | 
    63  | 
  | 
| 
 | 
    64  | 
\indexoutertoken{text}\indexouternonterm{comment}\indexouternonterm{interest}
 | 
| 
7046
 | 
    65  | 
\begin{rail}
 | 
| 
7167
 | 
    66  | 
  text: verbatim | nameref
  | 
| 
7050
 | 
    67  | 
  ;
  | 
| 
7167
 | 
    68  | 
  comment: '--' text
  | 
| 
7046
 | 
    69  | 
  ;
  | 
| 
7167
 | 
    70  | 
  interest: percent nat? | ppercent
  | 
| 
7046
 | 
    71  | 
  ;
  | 
| 
 | 
    72  | 
\end{rail}
 | 
| 
 | 
    73  | 
  | 
| 
 | 
    74  | 
  | 
| 
7175
 | 
    75  | 
\subsection{Type classes, Sorts and arities}
 | 
| 
7046
 | 
    76  | 
  | 
| 
7050
 | 
    77  | 
The syntax of sorts and arities is given directly at the outer level.  Note
  | 
| 
7167
 | 
    78  | 
that this is in contrast to that types and terms (see \ref{sec:types-terms}).
 | 
| 
7050
 | 
    79  | 
  | 
| 
 | 
    80  | 
\indexouternonterm{sort}\indexouternonterm{arity}\indexouternonterm{simplearity}
 | 
| 
7135
 | 
    81  | 
\indexouternonterm{classdecl}
 | 
| 
7046
 | 
    82  | 
\begin{rail}
 | 
| 
7167
 | 
    83  | 
  classdecl: name ('<' (nameref ',' +))?
 | 
| 
7046
 | 
    84  | 
  ;
  | 
| 
7167
 | 
    85  | 
  sort: nameref | lbrace (nameref * ',') rbrace
  | 
| 
7046
 | 
    86  | 
  ;
  | 
| 
7167
 | 
    87  | 
  arity: ('(' (sort + ',') ')')? sort
 | 
| 
7050
 | 
    88  | 
  ;
  | 
| 
7167
 | 
    89  | 
  simplearity: ('(' (sort + ',') ')')? nameref
 | 
| 
 | 
    90  | 
  ;
  | 
| 
7050
 | 
    91  | 
\end{rail}
 | 
| 
 | 
    92  | 
  | 
| 
 | 
    93  | 
  | 
| 
7167
 | 
    94  | 
\subsection{Types and terms}\label{sec:types-terms}
 | 
| 
7050
 | 
    95  | 
  | 
| 
7167
 | 
    96  | 
The actual inner Isabelle syntax, that of types and terms of the logic, is far
  | 
| 
 | 
    97  | 
too flexible in order to be modeled explicitly at the outer theory level.
  | 
| 
 | 
    98  | 
Basically, any such entity has to be quoted at the outer level to turn it into
  | 
| 
7175
 | 
    99  | 
a single token (the parsing and type-checking is performed later).  For
  | 
| 
 | 
   100  | 
convenience, a slightly more liberal convention is adopted: quotes may be
  | 
| 
 | 
   101  | 
omitted for any type or term that is already \emph{atomic at the outer level}.
 | 
| 
 | 
   102  | 
E.g.\ one may write just \texttt{x} instead of \texttt{"x"}.
 | 
| 
7050
 | 
   103  | 
  | 
| 
 | 
   104  | 
\indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
 | 
| 
 | 
   105  | 
\begin{rail}
 | 
| 
7167
 | 
   106  | 
  type: nameref | typefree | typevar
  | 
| 
7050
 | 
   107  | 
  ;
  | 
| 
7167
 | 
   108  | 
  term: nameref | var | textvar | nat
  | 
| 
7050
 | 
   109  | 
  ;
  | 
| 
7167
 | 
   110  | 
  prop: term
  | 
| 
7050
 | 
   111  | 
  ;
  | 
| 
 | 
   112  | 
\end{rail}
 | 
| 
 | 
   113  | 
  | 
| 
7167
 | 
   114  | 
Type declarations and definitions usually refer to \railnonterm{typespec} on
 | 
| 
 | 
   115  | 
the left-hand side.  This models basic type constructor application at the
  | 
| 
 | 
   116  | 
outer syntax level.  Note that only plain postfix notation is available here,
  | 
| 
 | 
   117  | 
but no infixes.
  | 
| 
7050
 | 
   118  | 
  | 
| 
 | 
   119  | 
\indexouternonterm{typespec}
 | 
| 
 | 
   120  | 
\begin{rail}
 | 
| 
7167
 | 
   121  | 
  typespec: (() | typefree | '(' ( typefree + ',' ) ')') name
 | 
| 
7050
 | 
   122  | 
  ;
  | 
| 
 | 
   123  | 
\end{rail}
 | 
| 
 | 
   124  | 
  | 
| 
 | 
   125  | 
  | 
| 
 | 
   126  | 
\subsection{Term patterns}
 | 
| 
 | 
   127  | 
  | 
| 
7167
 | 
   128  | 
Assumptions and goal statements usually admit automatic binding of schematic
  | 
| 
 | 
   129  | 
text variables by giving (optional) patterns of the form $\IS{p@1 \dots p@n}$.
 | 
| 
 | 
   130  | 
There are separate versions available for \railqtoken{term}s and
 | 
| 
 | 
   131  | 
\railqtoken{prop}s.  The latter provides a $\CONCLNAME$ part with patterns
 | 
| 
 | 
   132  | 
referring the (atomic) conclusion of a rule.
  | 
| 
7050
 | 
   133  | 
  | 
| 
 | 
   134  | 
\indexouternonterm{termpat}\indexouternonterm{proppat}
 | 
| 
 | 
   135  | 
\begin{rail}
 | 
| 
7167
 | 
   136  | 
  termpat: '(' ('is' term +) ')'
 | 
| 
7050
 | 
   137  | 
  ;
  | 
| 
7167
 | 
   138  | 
  proppat: '(' (('is' prop +) | 'concl' ('is' prop +) | ('is' prop +) 'concl' ('is' prop +)) ')'
 | 
| 
7046
 | 
   139  | 
  ;
  | 
| 
 | 
   140  | 
\end{rail}
 | 
| 
 | 
   141  | 
  | 
| 
 | 
   142  | 
  | 
| 
7050
 | 
   143  | 
\subsection{Mixfix annotations}
 | 
| 
 | 
   144  | 
  | 
| 
7134
 | 
   145  | 
Mixfix annotations specify concrete \emph{inner} syntax of Isabelle types and
 | 
| 
7167
 | 
   146  | 
terms.  Some commands such as $\TYPES$ admit infixes only, while $\CONSTS$ and
  | 
| 
 | 
   147  | 
$\isarkeyword{syntax}$ support the full range of general mixfixes and binders.
 | 
| 
7046
 | 
   148  | 
  | 
| 
7050
 | 
   149  | 
\indexouternonterm{infix}\indexouternonterm{mixfix}
 | 
| 
7046
 | 
   150  | 
\begin{rail}
 | 
| 
7167
 | 
   151  | 
  infix: '(' ('infixl' | 'infixr') string? nat ')'
 | 
| 
 | 
   152  | 
  ;
  | 
| 
7175
 | 
   153  | 
  mixfix: infix | '(' string prios? nat? ')' | '(' 'binder' string prios? nat ')'
 | 
| 
7050
 | 
   154  | 
  ;
  | 
| 
 | 
   155  | 
  | 
| 
7175
 | 
   156  | 
  prios: '[' (nat + ',') ']'
  | 
| 
7050
 | 
   157  | 
  ;
  | 
| 
7046
 | 
   158  | 
\end{rail}
 | 
| 
 | 
   159  | 
  | 
| 
7050
 | 
   160  | 
  | 
| 
7134
 | 
   161  | 
\subsection{Attributes and theorems}\label{sec:syn-att}
 | 
| 
7050
 | 
   162  | 
  | 
| 
 | 
   163  | 
Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
 | 
| 
 | 
   164  | 
``semi-inner'' syntax, which does not have to be atomic at the outer level
  | 
| 
 | 
   165  | 
unlike that of types and terms.  Instead, the attribute argument
  | 
| 
 | 
   166  | 
specifications may be any sequence of atomic entities (identifiers, strings
  | 
| 
7167
 | 
   167  | 
etc.), or properly bracketed argument lists.  Below \railqtoken{atom} refers
 | 
| 
7175
 | 
   168  | 
to any atomic entity, including \railtoken{keyword}s conforming to
 | 
| 
 | 
   169  | 
\railtoken{symident}.
 | 
| 
7050
 | 
   170  | 
  | 
| 
 | 
   171  | 
\indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
 | 
| 
 | 
   172  | 
\begin{rail}
 | 
| 
7167
 | 
   173  | 
  atom: nameref | typefree | typevar | var | textvar | nat | keyword
  | 
| 
7134
 | 
   174  | 
  ;
  | 
| 
7167
 | 
   175  | 
  arg: atom | '(' args ')' | '[' args ']' | lbrace args rbrace
 | 
| 
7050
 | 
   176  | 
  ;
  | 
| 
7167
 | 
   177  | 
  args: arg *
  | 
| 
7134
 | 
   178  | 
  ;
  | 
| 
7167
 | 
   179  | 
  attributes: '[' (nameref args * ',') ']'
  | 
| 
7050
 | 
   180  | 
  ;
  | 
| 
 | 
   181  | 
\end{rail}
 | 
| 
 | 
   182  | 
  | 
| 
7167
 | 
   183  | 
Theorem specifications come in several flavors: \railnonterm{axmdecl} and
 | 
| 
7175
 | 
   184  | 
\railnonterm{thmdecl} usually refer to axioms, assumptions or results of goal
 | 
| 
 | 
   185  | 
statements, \railnonterm{thmdef} collects lists of existing theorems.
 | 
| 
 | 
   186  | 
Existing theorems are given by \railnonterm{thmref} and \railnonterm{thmrefs}
 | 
| 
 | 
   187  | 
(the former requires an actual singleton result).  Any of these theorem
  | 
| 
 | 
   188  | 
specifications may include lists of attributes both on the left and right hand
  | 
| 
 | 
   189  | 
sides; attributes are applied to the any immediately preceding theorem.
  | 
| 
7050
 | 
   190  | 
  | 
| 
7135
 | 
   191  | 
\indexouternonterm{thmdecl}\indexouternonterm{axmdecl}
 | 
| 
 | 
   192  | 
\indexouternonterm{thmdef}\indexouternonterm{thmrefs}
 | 
| 
7050
 | 
   193  | 
\begin{rail}
 | 
| 
7167
 | 
   194  | 
  axmdecl: name attributes? ':'
  | 
| 
7050
 | 
   195  | 
  ;
  | 
| 
7167
 | 
   196  | 
  thmdecl: thmname ':'
  | 
| 
7135
 | 
   197  | 
  ;
  | 
| 
7167
 | 
   198  | 
  thmdef: thmname '='
  | 
| 
7050
 | 
   199  | 
  ;
  | 
| 
7175
 | 
   200  | 
  thmref: nameref attributes?
  | 
| 
 | 
   201  | 
  ;
  | 
| 
 | 
   202  | 
  thmrefs: thmref +
  | 
| 
7134
 | 
   203  | 
  ;
  | 
| 
7167
 | 
   204  | 
  | 
| 
 | 
   205  | 
  thmname: name attributes | name | attributes
  | 
| 
7050
 | 
   206  | 
  ;
  | 
| 
 | 
   207  | 
\end{rail}
 | 
| 
7046
 | 
   208  | 
  | 
| 
 | 
   209  | 
  | 
| 
7050
 | 
   210  | 
\subsection{Proof methods}\label{sec:syn-meth}
 | 
| 
7046
 | 
   211  | 
  | 
| 
7050
 | 
   212  | 
Proof methods are either basic ones, or expressions composed of methods via
  | 
| 
7175
 | 
   213  | 
``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternative choices),
 | 
| 
7167
 | 
   214  | 
``\texttt{?}'' (try), ``\texttt{*}'' (repeat ${} \ge 0$ times), ``\texttt{+}''
 | 
| 
 | 
   215  | 
(repeat ${} > 0$ times).  In practice, proof methods are usually just a comma
 | 
| 
7175
 | 
   216  | 
separated list of (\railqtoken{nameref}~\railnonterm{args}) specifications.
 | 
| 
7167
 | 
   217  | 
Thus the syntax is similar to that of attributes, with plain parentheses
  | 
| 
 | 
   218  | 
instead of square brackets (see also \S\ref{sec:syn-att}).  Note that
 | 
| 
 | 
   219  | 
parentheses may be dropped for single method specifications without arguments.
  | 
| 
7046
 | 
   220  | 
  | 
| 
7050
 | 
   221  | 
\indexouternonterm{method}
 | 
| 
 | 
   222  | 
\begin{rail}
 | 
| 
7167
 | 
   223  | 
  method: (nameref | '(' methods ')') (() | '?' | '*' | '+')
 | 
| 
7134
 | 
   224  | 
  ;
  | 
| 
7167
 | 
   225  | 
  methods: (nameref args | method) + (',' | '|')
 | 
| 
7050
 | 
   226  | 
  ;
  | 
| 
 | 
   227  | 
\end{rail}
 | 
| 
7046
 | 
   228  | 
  | 
| 
 | 
   229  | 
  | 
| 
 | 
   230  | 
%%% Local Variables: 
  | 
| 
 | 
   231  | 
%%% mode: latex
  | 
| 
 | 
   232  | 
%%% TeX-master: "isar-ref"
  | 
| 
 | 
   233  | 
%%% End: 
  |