author | wenzelm |
Sun, 31 Oct 2010 13:26:37 +0100 | |
changeset 40296 | ac4d75f86d97 |
parent 40291 | 012ed4426fda |
child 40406 | 313a24b66a8d |
permissions | -rw-r--r-- |
27037 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Outer{\isacharunderscore}Syntax}% |
|
4 |
% |
|
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
\isacommand{theory}\isamarkupfalse% |
|
11 |
\ Outer{\isacharunderscore}Syntax\isanewline |
|
27052 | 12 |
\isakeyword{imports}\ Main\isanewline |
27037 | 13 |
\isakeyword{begin}% |
14 |
\endisatagtheory |
|
15 |
{\isafoldtheory}% |
|
16 |
% |
|
17 |
\isadelimtheory |
|
18 |
% |
|
19 |
\endisadelimtheory |
|
20 |
% |
|
27042 | 21 |
\isamarkupchapter{Outer syntax% |
27037 | 22 |
} |
23 |
\isamarkuptrue% |
|
24 |
% |
|
25 |
\begin{isamarkuptext}% |
|
26 |
The rather generic framework of Isabelle/Isar syntax emerges from |
|
27 |
three main syntactic categories: \emph{commands} of the top-level |
|
28 |
Isar engine (covering theory and proof elements), \emph{methods} for |
|
29 |
general goal refinements (analogous to traditional ``tactics''), and |
|
30 |
\emph{attributes} for operations on facts (within a certain |
|
31 |
context). Subsequently we give a reference of basic syntactic |
|
32 |
entities underlying Isabelle/Isar syntax in a bottom-up manner. |
|
33 |
Concrete theory and proof language elements will be introduced later |
|
34 |
on. |
|
35 |
||
36 |
\medskip In order to get started with writing well-formed |
|
37 |
Isabelle/Isar documents, the most important aspect to be noted is |
|
38 |
the difference of \emph{inner} versus \emph{outer} syntax. Inner |
|
39 |
syntax is that of Isabelle types and terms of the logic, while outer |
|
40 |
syntax is that of Isabelle/Isar theory sources (specifications and |
|
41 |
proofs). As a general rule, inner syntax entities may occur only as |
|
42 |
\emph{atomic entities} within outer syntax. For example, the string |
|
43 |
\verb|"x + y"| and identifier \verb|z| are legal term |
|
44 |
specifications within a theory, while \verb|x + y| without |
|
45 |
quotes is not. |
|
46 |
||
47 |
Printed theory documents usually omit quotes to gain readability |
|
48 |
(this is a matter of {\LaTeX} macro setup, say via \verb|\isabellestyle|, see also \cite{isabelle-sys}). Experienced |
|
49 |
users of Isabelle/Isar may easily reconstruct the lost technical |
|
50 |
information, while mere readers need not care about quotes at all. |
|
51 |
||
52 |
\medskip Isabelle/Isar input may contain any number of input |
|
53 |
termination characters ``\verb|;|'' (semicolon) to separate |
|
54 |
commands explicitly. This is particularly useful in interactive |
|
55 |
shell sessions to make clear where the current command is intended |
|
56 |
to end. Otherwise, the interpreter loop will continue to issue a |
|
57 |
secondary prompt ``\verb|#|'' until an end-of-command is |
|
58 |
clearly recognized from the input syntax, e.g.\ encounter of the |
|
59 |
next command keyword. |
|
60 |
||
61 |
More advanced interfaces such as Proof~General \cite{proofgeneral} |
|
62 |
do not require explicit semicolons, the amount of input text is |
|
63 |
determined automatically by inspecting the present content of the |
|
64 |
Emacs text buffer. In the printed presentation of Isabelle/Isar |
|
65 |
documents semicolons are omitted altogether for readability. |
|
66 |
||
67 |
\begin{warn} |
|
68 |
Proof~General requires certain syntax classification tables in |
|
69 |
order to achieve properly synchronized interaction with the |
|
70 |
Isabelle/Isar process. These tables need to be consistent with |
|
71 |
the Isabelle version and particular logic image to be used in a |
|
72 |
running session (common object-logics may well change the outer |
|
73 |
syntax). The standard setup should work correctly with any of the |
|
74 |
``official'' logic images derived from Isabelle/HOL (including |
|
75 |
HOLCF etc.). Users of alternative logics may need to tell |
|
76 |
Proof~General explicitly, e.g.\ by giving an option \verb|-k ZF| |
|
77 |
(in conjunction with \verb|-l ZF|, to specify the default |
|
78 |
logic image). Note that option \verb|-L| does both |
|
79 |
of this at the same time. |
|
80 |
\end{warn}% |
|
81 |
\end{isamarkuptext}% |
|
82 |
\isamarkuptrue% |
|
83 |
% |
|
28788 | 84 |
\isamarkupsection{Lexical matters \label{sec:outer-lex}% |
27037 | 85 |
} |
86 |
\isamarkuptrue% |
|
87 |
% |
|
88 |
\begin{isamarkuptext}% |
|
28788 | 89 |
The outer lexical syntax consists of three main categories of |
90 |
syntax tokens: |
|
91 |
||
92 |
\begin{enumerate} |
|
93 |
||
94 |
\item \emph{major keywords} --- the command names that are available |
|
95 |
in the present logic session; |
|
96 |
||
97 |
\item \emph{minor keywords} --- additional literal tokens required |
|
98 |
by the syntax of commands; |
|
99 |
||
100 |
\item \emph{named tokens} --- various categories of identifiers etc. |
|
101 |
||
102 |
\end{enumerate} |
|
27037 | 103 |
|
28788 | 104 |
Major keywords and minor keywords are guaranteed to be disjoint. |
105 |
This helps user-interfaces to determine the overall structure of a |
|
106 |
theory text, without knowing the full details of command syntax. |
|
107 |
Internally, there is some additional information about the kind of |
|
108 |
major keywords, which approximates the command type (theory command, |
|
109 |
proof command etc.). |
|
110 |
||
111 |
Keywords override named tokens. For example, the presence of a |
|
112 |
command called \verb|term| inhibits the identifier \verb|term|, but the string \verb|"term"| can be used instead. |
|
113 |
By convention, the outer syntax always allows quoted strings in |
|
114 |
addition to identifiers, wherever a named entity is expected. |
|
115 |
||
116 |
When tokenizing a given input sequence, the lexer repeatedly takes |
|
117 |
the longest prefix of the input that forms a valid token. Spaces, |
|
118 |
tabs, newlines and formfeeds between tokens serve as explicit |
|
119 |
separators. |
|
120 |
||
121 |
\medskip The categories for named tokens are defined once and for |
|
122 |
all as follows. |
|
27037 | 123 |
|
28788 | 124 |
\begin{center} |
125 |
\begin{supertabular}{rcl} |
|
126 |
\indexdef{}{syntax}{ident}\hypertarget{syntax.ident}{\hyperlink{syntax.ident}{\mbox{\isa{ident}}}} & = & \isa{{\isachardoublequote}letter\ quasiletter\isactrlsup {\isacharasterisk}{\isachardoublequote}} \\ |
|
127 |
\indexdef{}{syntax}{longident}\hypertarget{syntax.longident}{\hyperlink{syntax.longident}{\mbox{\isa{longident}}}} & = & \isa{{\isachardoublequote}ident{\isacharparenleft}{\isachardoublequote}}\verb|.|\isa{{\isachardoublequote}ident{\isacharparenright}\isactrlsup {\isacharplus}{\isachardoublequote}} \\ |
|
128 |
\indexdef{}{syntax}{symident}\hypertarget{syntax.symident}{\hyperlink{syntax.symident}{\mbox{\isa{symident}}}} & = & \isa{{\isachardoublequote}sym\isactrlsup {\isacharplus}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\|\verb|<|\isa{ident}\verb|>| \\ |
|
129 |
\indexdef{}{syntax}{nat}\hypertarget{syntax.nat}{\hyperlink{syntax.nat}{\mbox{\isa{nat}}}} & = & \isa{{\isachardoublequote}digit\isactrlsup {\isacharplus}{\isachardoublequote}} \\ |
|
40290
47f572aff50a
support for floating-point tokens in outer syntax (coinciding with inner syntax version);
wenzelm
parents:
35841
diff
changeset
|
130 |
\indexdef{}{syntax}{float}\hypertarget{syntax.float}{\hyperlink{syntax.float}{\mbox{\isa{float}}}} & = & \indexref{}{syntax}{nat}\hyperlink{syntax.nat}{\mbox{\isa{nat}}}\verb|.|\indexref{}{syntax}{nat}\hyperlink{syntax.nat}{\mbox{\isa{nat}}}\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|-|\indexref{}{syntax}{nat}\hyperlink{syntax.nat}{\mbox{\isa{nat}}}\verb|.|\indexref{}{syntax}{nat}\hyperlink{syntax.nat}{\mbox{\isa{nat}}} \\ |
28788 | 131 |
\indexdef{}{syntax}{var}\hypertarget{syntax.var}{\hyperlink{syntax.var}{\mbox{\isa{var}}}} & = & \verb|?|\isa{{\isachardoublequote}ident\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|?|\isa{ident}\verb|.|\isa{nat} \\ |
132 |
\indexdef{}{syntax}{typefree}\hypertarget{syntax.typefree}{\hyperlink{syntax.typefree}{\mbox{\isa{typefree}}}} & = & \verb|'|\isa{ident} \\ |
|
133 |
\indexdef{}{syntax}{typevar}\hypertarget{syntax.typevar}{\hyperlink{syntax.typevar}{\mbox{\isa{typevar}}}} & = & \verb|?|\isa{{\isachardoublequote}typefree\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|?|\isa{typefree}\verb|.|\isa{nat} \\ |
|
134 |
\indexdef{}{syntax}{string}\hypertarget{syntax.string}{\hyperlink{syntax.string}{\mbox{\isa{string}}}} & = & \verb|"| \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}} \verb|"| \\ |
|
135 |
\indexdef{}{syntax}{altstring}\hypertarget{syntax.altstring}{\hyperlink{syntax.altstring}{\mbox{\isa{altstring}}}} & = & \verb|`| \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}} \verb|`| \\ |
|
136 |
\indexdef{}{syntax}{verbatim}\hypertarget{syntax.verbatim}{\hyperlink{syntax.verbatim}{\mbox{\isa{verbatim}}}} & = & \verb|{*| \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}} \verb|*|\verb|}| \\[1ex] |
|
27037 | 137 |
|
28788 | 138 |
\isa{letter} & = & \isa{{\isachardoublequote}latin\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\|\verb|<|\isa{latin}\verb|>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\|\verb|<|\isa{{\isachardoublequote}latin\ latin{\isachardoublequote}}\verb|>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ greek\ \ {\isacharbar}{\isachardoublequote}} \\ |
139 |
& & \verb|\<^isub>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<^isup>| \\ |
|
140 |
\isa{quasiletter} & = & \isa{{\isachardoublequote}letter\ \ {\isacharbar}\ \ digit\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|_|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|'| \\ |
|
141 |
\isa{latin} & = & \verb|a|\isa{{\isachardoublequote}\ \ {\isacharbar}\ {\isasymdots}\ {\isacharbar}\ \ {\isachardoublequote}}\verb|z|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|A|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isasymdots}\ {\isacharbar}\ \ {\isachardoublequote}}\verb|Z| \\ |
|
142 |
\isa{digit} & = & \verb|0|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isasymdots}\ {\isacharbar}\ \ {\isachardoublequote}}\verb|9| \\ |
|
143 |
\isa{sym} & = & \verb|!|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|#|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|$|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|%|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|&|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|*|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|+|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|-|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|/|\isa{{\isachardoublequote}\ \ {\isacharbar}{\isachardoublequote}} \\ |
|
144 |
& & \verb|<|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|=|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|?|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|@|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|^|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|_|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb||\verb,|,\verb||\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|~| \\ |
|
145 |
\isa{greek} & = & \verb|\<alpha>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<beta>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<gamma>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<delta>|\isa{{\isachardoublequote}\ \ {\isacharbar}{\isachardoublequote}} \\ |
|
146 |
& & \verb|\<epsilon>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<zeta>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<eta>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<theta>|\isa{{\isachardoublequote}\ \ {\isacharbar}{\isachardoublequote}} \\ |
|
147 |
& & \verb|\<iota>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<kappa>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<mu>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<nu>|\isa{{\isachardoublequote}\ \ {\isacharbar}{\isachardoublequote}} \\ |
|
148 |
& & \verb|\<xi>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<pi>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<rho>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<sigma>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<tau>|\isa{{\isachardoublequote}\ \ {\isacharbar}{\isachardoublequote}} \\ |
|
149 |
& & \verb|\<upsilon>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<phi>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<chi>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<psi>|\isa{{\isachardoublequote}\ \ {\isacharbar}{\isachardoublequote}} \\ |
|
150 |
& & \verb|\<omega>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<Gamma>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<Delta>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<Theta>|\isa{{\isachardoublequote}\ \ {\isacharbar}{\isachardoublequote}} \\ |
|
151 |
& & \verb|\<Lambda>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<Xi>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<Pi>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<Sigma>|\isa{{\isachardoublequote}\ \ {\isacharbar}{\isachardoublequote}} \\ |
|
152 |
& & \verb|\<Upsilon>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<Phi>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<Psi>|\isa{{\isachardoublequote}\ \ {\isacharbar}\ \ {\isachardoublequote}}\verb|\<Omega>| \\ |
|
153 |
\end{supertabular} |
|
154 |
\end{center} |
|
155 |
||
156 |
A \indexref{}{syntax}{var}\hyperlink{syntax.var}{\mbox{\isa{var}}} or \indexref{}{syntax}{typevar}\hyperlink{syntax.typevar}{\mbox{\isa{typevar}}} describes an unknown, |
|
157 |
which is internally a pair of base name and index (ML type \verb|indexname|). These components are either separated by a dot as in |
|
158 |
\isa{{\isachardoublequote}{\isacharquery}x{\isachardot}{\isadigit{1}}{\isachardoublequote}} or \isa{{\isachardoublequote}{\isacharquery}x{\isadigit{7}}{\isachardot}{\isadigit{3}}{\isachardoublequote}} or run together as in \isa{{\isachardoublequote}{\isacharquery}x{\isadigit{1}}{\isachardoublequote}}. The latter form is possible if the base name does not end |
|
159 |
with digits. If the index is 0, it may be dropped altogether: |
|
160 |
\isa{{\isachardoublequote}{\isacharquery}x{\isachardoublequote}} and \isa{{\isachardoublequote}{\isacharquery}x{\isadigit{0}}{\isachardoublequote}} and \isa{{\isachardoublequote}{\isacharquery}x{\isachardot}{\isadigit{0}}{\isachardoublequote}} all refer to the |
|
161 |
same unknown, with basename \isa{{\isachardoublequote}x{\isachardoublequote}} and index 0. |
|
162 |
||
163 |
The syntax of \indexref{}{syntax}{string}\hyperlink{syntax.string}{\mbox{\isa{string}}} admits any characters, including |
|
27037 | 164 |
newlines; ``\verb|"|'' (double-quote) and ``\verb|\|'' (backslash) need to be escaped by a backslash; arbitrary |
165 |
character codes may be specified as ``\verb|\|\isa{ddd}'', |
|
166 |
with three decimal digits. Alternative strings according to |
|
28788 | 167 |
\indexref{}{syntax}{altstring}\hyperlink{syntax.altstring}{\mbox{\isa{altstring}}} are analogous, using single back-quotes |
168 |
instead. |
|
169 |
||
170 |
The body of \indexref{}{syntax}{verbatim}\hyperlink{syntax.verbatim}{\mbox{\isa{verbatim}}} may consist of any text not |
|
27037 | 171 |
containing ``\verb|*|\verb|}|''; this allows |
28788 | 172 |
convenient inclusion of quotes without further escapes. There is no |
173 |
way to escape ``\verb|*|\verb|}|''. If the quoted |
|
174 |
text is {\LaTeX} source, one may usually add some blank or comment |
|
175 |
to avoid the critical character sequence. |
|
176 |
||
177 |
Source comments take the form \verb|(*|~\isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}~\verb|*)| and may be nested, although the user-interface |
|
178 |
might prevent this. Note that this form indicates source comments |
|
179 |
only, which are stripped after lexical analysis of the input. The |
|
180 |
Isar syntax also provides proper \emph{document comments} that are |
|
181 |
considered as part of the text (see \secref{sec:comments}). |
|
27037 | 182 |
|
183 |
Common mathematical symbols such as \isa{{\isasymforall}} are represented in |
|
184 |
Isabelle as \verb|\<forall>|. There are infinitely many Isabelle |
|
185 |
symbols like this, although proper presentation is left to front-end |
|
186 |
tools such as {\LaTeX} or Proof~General with the X-Symbol package. |
|
29722 | 187 |
A list of predefined Isabelle symbols that work well with these |
188 |
tools is given in \appref{app:symbols}. Note that \verb|\<lambda>| |
|
189 |
does not belong to the \isa{letter} category, since it is already |
|
190 |
used differently in the Pure term language.% |
|
27037 | 191 |
\end{isamarkuptext}% |
192 |
\isamarkuptrue% |
|
193 |
% |
|
194 |
\isamarkupsection{Common syntax entities% |
|
195 |
} |
|
196 |
\isamarkuptrue% |
|
197 |
% |
|
198 |
\begin{isamarkuptext}% |
|
199 |
We now introduce several basic syntactic entities, such as names, |
|
200 |
terms, and theorem specifications, which are factored out of the |
|
201 |
actual Isar language elements to be described later.% |
|
202 |
\end{isamarkuptext}% |
|
203 |
\isamarkuptrue% |
|
204 |
% |
|
205 |
\isamarkupsubsection{Names% |
|
206 |
} |
|
207 |
\isamarkuptrue% |
|
208 |
% |
|
209 |
\begin{isamarkuptext}% |
|
210 |
Entity \railqtok{name} usually refers to any name of types, |
|
211 |
constants, theorems etc.\ that are to be \emph{declared} or |
|
212 |
\emph{defined} (so qualified identifiers are excluded here). Quoted |
|
213 |
strings provide an escape for non-identifier names or those ruled |
|
214 |
out by outer syntax keywords (e.g.\ quoted \verb|"let"|). |
|
215 |
Already existing objects are usually referenced by |
|
216 |
\railqtok{nameref}. |
|
217 |
||
218 |
\indexoutertoken{name}\indexoutertoken{parname}\indexoutertoken{nameref} |
|
219 |
\begin{rail} |
|
220 |
name: ident | symident | string | nat |
|
221 |
; |
|
222 |
parname: '(' name ')' |
|
223 |
; |
|
224 |
nameref: name | longident |
|
225 |
; |
|
40296 | 226 |
\end{rail}% |
227 |
\end{isamarkuptext}% |
|
228 |
\isamarkuptrue% |
|
229 |
% |
|
230 |
\isamarkupsubsection{Numbers% |
|
231 |
} |
|
232 |
\isamarkuptrue% |
|
233 |
% |
|
234 |
\begin{isamarkuptext}% |
|
235 |
The outer lexical syntax (\secref{sec:outer-lex}) admits |
|
236 |
natural numbers and floating point numbers. These are combined as |
|
237 |
\hyperlink{syntax.int}{\mbox{\isa{int}}} and \hyperlink{syntax.real}{\mbox{\isa{real}}} as follows. |
|
238 |
||
239 |
\indexoutertoken{int}\indexoutertoken{real} |
|
240 |
\begin{rail} |
|
27037 | 241 |
int: nat | '-' nat |
242 |
; |
|
40296 | 243 |
real: float | int |
244 |
; |
|
245 |
\end{rail} |
|
246 |
||
247 |
Note that there is an overlap with the category \railqtok{name}, |
|
248 |
which also includes \hyperlink{syntax.nat}{\mbox{\isa{nat}}}.% |
|
27037 | 249 |
\end{isamarkuptext}% |
250 |
\isamarkuptrue% |
|
251 |
% |
|
252 |
\isamarkupsubsection{Comments \label{sec:comments}% |
|
253 |
} |
|
254 |
\isamarkuptrue% |
|
255 |
% |
|
256 |
\begin{isamarkuptext}% |
|
257 |
Large chunks of plain \railqtok{text} are usually given |
|
258 |
\railtok{verbatim}, i.e.\ enclosed in \verb|{|\verb|*|~\isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}~\verb|*|\verb|}|. For convenience, |
|
259 |
any of the smaller text units conforming to \railqtok{nameref} are |
|
260 |
admitted as well. A marginal \railnonterm{comment} is of the form |
|
261 |
\verb|--| \railqtok{text}. Any number of these may occur |
|
262 |
within Isabelle/Isar commands. |
|
263 |
||
264 |
\indexoutertoken{text}\indexouternonterm{comment} |
|
265 |
\begin{rail} |
|
266 |
text: verbatim | nameref |
|
267 |
; |
|
268 |
comment: '--' text |
|
269 |
; |
|
270 |
\end{rail}% |
|
271 |
\end{isamarkuptext}% |
|
272 |
\isamarkuptrue% |
|
273 |
% |
|
274 |
\isamarkupsubsection{Type classes, sorts and arities% |
|
275 |
} |
|
276 |
\isamarkuptrue% |
|
277 |
% |
|
278 |
\begin{isamarkuptext}% |
|
279 |
Classes are specified by plain names. Sorts have a very simple |
|
280 |
inner syntax, which is either a single class name \isa{c} or a |
|
281 |
list \isa{{\isachardoublequote}{\isacharbraceleft}c\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n{\isacharbraceright}{\isachardoublequote}} referring to the |
|
282 |
intersection of these classes. The syntax of type arities is given |
|
283 |
directly at the outer level. |
|
284 |
||
285 |
\indexouternonterm{sort}\indexouternonterm{arity} |
|
286 |
\indexouternonterm{classdecl} |
|
287 |
\begin{rail} |
|
288 |
classdecl: name (('<' | subseteq) (nameref + ','))? |
|
289 |
; |
|
290 |
sort: nameref |
|
291 |
; |
|
292 |
arity: ('(' (sort + ',') ')')? sort |
|
293 |
; |
|
294 |
\end{rail}% |
|
295 |
\end{isamarkuptext}% |
|
296 |
\isamarkuptrue% |
|
297 |
% |
|
298 |
\isamarkupsubsection{Types and terms \label{sec:types-terms}% |
|
299 |
} |
|
300 |
\isamarkuptrue% |
|
301 |
% |
|
302 |
\begin{isamarkuptext}% |
|
303 |
The actual inner Isabelle syntax, that of types and terms of the |
|
304 |
logic, is far too sophisticated in order to be modelled explicitly |
|
305 |
at the outer theory level. Basically, any such entity has to be |
|
306 |
quoted to turn it into a single token (the parsing and type-checking |
|
307 |
is performed internally later). For convenience, a slightly more |
|
308 |
liberal convention is adopted: quotes may be omitted for any type or |
|
309 |
term that is already atomic at the outer level. For example, one |
|
310 |
may just write \verb|x| instead of quoted \verb|"x"|. |
|
311 |
Note that symbolic identifiers (e.g.\ \verb|++| or \isa{{\isachardoublequote}{\isasymforall}{\isachardoublequote}} are available as well, provided these have not been superseded |
|
312 |
by commands or other keywords already (such as \verb|=| or |
|
313 |
\verb|+|). |
|
314 |
||
315 |
\indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop} |
|
316 |
\begin{rail} |
|
317 |
type: nameref | typefree | typevar |
|
318 |
; |
|
319 |
term: nameref | var |
|
320 |
; |
|
321 |
prop: term |
|
322 |
; |
|
323 |
\end{rail} |
|
324 |
||
325 |
Positional instantiations are indicated by giving a sequence of |
|
326 |
terms, or the placeholder ``\isa{{\isacharunderscore}}'' (underscore), which means to |
|
327 |
skip a position. |
|
328 |
||
329 |
\indexoutertoken{inst}\indexoutertoken{insts} |
|
330 |
\begin{rail} |
|
331 |
inst: underscore | term |
|
332 |
; |
|
333 |
insts: (inst *) |
|
334 |
; |
|
335 |
\end{rail} |
|
336 |
||
337 |
Type declarations and definitions usually refer to |
|
338 |
\railnonterm{typespec} on the left-hand side. This models basic |
|
339 |
type constructor application at the outer syntax level. Note that |
|
340 |
only plain postfix notation is available here, but no infixes. |
|
341 |
||
342 |
\indexouternonterm{typespec} |
|
35841 | 343 |
\indexouternonterm{typespecsorts} |
27037 | 344 |
\begin{rail} |
345 |
typespec: (() | typefree | '(' ( typefree + ',' ) ')') name |
|
346 |
; |
|
35841 | 347 |
|
348 |
typespecsorts: (() | (typefree ('::' sort)?) | '(' ( (typefree ('::' sort)?) + ',' ) ')') name |
|
349 |
; |
|
27037 | 350 |
\end{rail}% |
351 |
\end{isamarkuptext}% |
|
352 |
\isamarkuptrue% |
|
353 |
% |
|
354 |
\isamarkupsubsection{Term patterns and declarations \label{sec:term-decls}% |
|
355 |
} |
|
356 |
\isamarkuptrue% |
|
357 |
% |
|
358 |
\begin{isamarkuptext}% |
|
359 |
Wherever explicit propositions (or term fragments) occur in a proof |
|
360 |
text, casual binding of schematic term variables may be given |
|
361 |
specified via patterns of the form ``\isa{{\isachardoublequote}{\isacharparenleft}{\isasymIS}\ p\isactrlsub {\isadigit{1}}\ {\isasymdots}\ p\isactrlsub n{\isacharparenright}{\isachardoublequote}}''. This works both for \railqtok{term} and \railqtok{prop}. |
|
362 |
||
363 |
\indexouternonterm{termpat}\indexouternonterm{proppat} |
|
364 |
\begin{rail} |
|
365 |
termpat: '(' ('is' term +) ')' |
|
366 |
; |
|
367 |
proppat: '(' ('is' prop +) ')' |
|
368 |
; |
|
369 |
\end{rail} |
|
370 |
||
371 |
\medskip Declarations of local variables \isa{{\isachardoublequote}x\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}{\isachardoublequote}} and |
|
372 |
logical propositions \isa{{\isachardoublequote}a\ {\isacharcolon}\ {\isasymphi}{\isachardoublequote}} represent different views on |
|
373 |
the same principle of introducing a local scope. In practice, one |
|
374 |
may usually omit the typing of \railnonterm{vars} (due to |
|
375 |
type-inference), and the naming of propositions (due to implicit |
|
376 |
references of current facts). In any case, Isar proof elements |
|
377 |
usually admit to introduce multiple such items simultaneously. |
|
378 |
||
379 |
\indexouternonterm{vars}\indexouternonterm{props} |
|
380 |
\begin{rail} |
|
381 |
vars: (name+) ('::' type)? |
|
382 |
; |
|
383 |
props: thmdecl? (prop proppat? +) |
|
384 |
; |
|
385 |
\end{rail} |
|
386 |
||
387 |
The treatment of multiple declarations corresponds to the |
|
388 |
complementary focus of \railnonterm{vars} versus |
|
389 |
\railnonterm{props}. In ``\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}{\isachardoublequote}}'' |
|
390 |
the typing refers to all variables, while in \isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n{\isachardoublequote}} the naming refers to all propositions collectively. |
|
391 |
Isar language elements that refer to \railnonterm{vars} or |
|
392 |
\railnonterm{props} typically admit separate typings or namings via |
|
393 |
another level of iteration, with explicit \indexref{}{keyword}{and}\hyperlink{keyword.and}{\mbox{\isa{\isakeyword{and}}}} |
|
394 |
separators; e.g.\ see \hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}} and \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}} in |
|
395 |
\secref{sec:proof-context}.% |
|
396 |
\end{isamarkuptext}% |
|
397 |
\isamarkuptrue% |
|
398 |
% |
|
28788 | 399 |
\isamarkupsubsection{Attributes and theorems \label{sec:syn-att}% |
400 |
} |
|
401 |
\isamarkuptrue% |
|
402 |
% |
|
403 |
\begin{isamarkuptext}% |
|
404 |
Attributes have their own ``semi-inner'' syntax, in the sense |
|
405 |
that input conforming to \railnonterm{args} below is parsed by the |
|
406 |
attribute a second time. The attribute argument specifications may |
|
407 |
be any sequence of atomic entities (identifiers, strings etc.), or |
|
408 |
properly bracketed argument lists. Below \railqtok{atom} refers to |
|
409 |
any atomic entity, including any \railtok{keyword} conforming to |
|
410 |
\railtok{symident}. |
|
411 |
||
412 |
\indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes} |
|
413 |
\begin{rail} |
|
40291 | 414 |
atom: nameref | typefree | typevar | var | nat | float | keyword |
28788 | 415 |
; |
416 |
arg: atom | '(' args ')' | '[' args ']' |
|
417 |
; |
|
418 |
args: arg * |
|
419 |
; |
|
420 |
attributes: '[' (nameref args * ',') ']' |
|
421 |
; |
|
422 |
\end{rail} |
|
423 |
||
424 |
Theorem specifications come in several flavors: |
|
425 |
\railnonterm{axmdecl} and \railnonterm{thmdecl} usually refer to |
|
426 |
axioms, assumptions or results of goal statements, while |
|
427 |
\railnonterm{thmdef} collects lists of existing theorems. Existing |
|
428 |
theorems are given by \railnonterm{thmref} and |
|
429 |
\railnonterm{thmrefs}, the former requires an actual singleton |
|
430 |
result. |
|
431 |
||
432 |
There are three forms of theorem references: |
|
433 |
\begin{enumerate} |
|
434 |
||
435 |
\item named facts \isa{{\isachardoublequote}a{\isachardoublequote}}, |
|
436 |
||
437 |
\item selections from named facts \isa{{\isachardoublequote}a{\isacharparenleft}i{\isacharparenright}{\isachardoublequote}} or \isa{{\isachardoublequote}a{\isacharparenleft}j\ {\isacharminus}\ k{\isacharparenright}{\isachardoublequote}}, |
|
438 |
||
439 |
\item literal fact propositions using \indexref{}{syntax}{altstring}\hyperlink{syntax.altstring}{\mbox{\isa{altstring}}} syntax |
|
440 |
\verb|`|\isa{{\isachardoublequote}{\isasymphi}{\isachardoublequote}}\verb|`| (see also method |
|
441 |
\indexref{}{method}{fact}\hyperlink{method.fact}{\mbox{\isa{fact}}}). |
|
442 |
||
443 |
\end{enumerate} |
|
444 |
||
445 |
Any kind of theorem specification may include lists of attributes |
|
446 |
both on the left and right hand sides; attributes are applied to any |
|
447 |
immediately preceding fact. If names are omitted, the theorems are |
|
448 |
not stored within the theorem database of the theory or proof |
|
449 |
context, but any given attributes are applied nonetheless. |
|
450 |
||
451 |
An extra pair of brackets around attributes (like ``\isa{{\isachardoublequote}{\isacharbrackleft}{\isacharbrackleft}simproc\ a{\isacharbrackright}{\isacharbrackright}{\isachardoublequote}}'') abbreviates a theorem reference involving an |
|
452 |
internal dummy fact, which will be ignored later on. So only the |
|
453 |
effect of the attribute on the background context will persist. |
|
454 |
This form of in-place declarations is particularly useful with |
|
455 |
commands like \hyperlink{command.declare}{\mbox{\isa{\isacommand{declare}}}} and \hyperlink{command.using}{\mbox{\isa{\isacommand{using}}}}. |
|
456 |
||
457 |
\indexouternonterm{axmdecl}\indexouternonterm{thmdecl} |
|
458 |
\indexouternonterm{thmdef}\indexouternonterm{thmref} |
|
459 |
\indexouternonterm{thmrefs}\indexouternonterm{selection} |
|
460 |
\begin{rail} |
|
461 |
axmdecl: name attributes? ':' |
|
462 |
; |
|
463 |
thmdecl: thmbind ':' |
|
464 |
; |
|
465 |
thmdef: thmbind '=' |
|
466 |
; |
|
467 |
thmref: (nameref selection? | altstring) attributes? | '[' attributes ']' |
|
468 |
; |
|
469 |
thmrefs: thmref + |
|
470 |
; |
|
471 |
||
472 |
thmbind: name attributes | name | attributes |
|
473 |
; |
|
474 |
selection: '(' ((nat | nat '-' nat?) + ',') ')' |
|
475 |
; |
|
476 |
\end{rail}% |
|
477 |
\end{isamarkuptext}% |
|
478 |
\isamarkuptrue% |
|
479 |
% |
|
27037 | 480 |
\isadelimtheory |
481 |
% |
|
482 |
\endisadelimtheory |
|
483 |
% |
|
484 |
\isatagtheory |
|
485 |
\isacommand{end}\isamarkupfalse% |
|
486 |
% |
|
487 |
\endisatagtheory |
|
488 |
{\isafoldtheory}% |
|
489 |
% |
|
490 |
\isadelimtheory |
|
491 |
% |
|
492 |
\endisadelimtheory |
|
493 |
\isanewline |
|
494 |
\end{isabellebody}% |
|
495 |
%%% Local Variables: |
|
496 |
%%% mode: latex |
|
497 |
%%% TeX-master: "root" |
|
498 |
%%% End: |