doc-src/IsarRef/syntax.tex
author wenzelm
Fri, 30 Jul 1999 14:59:32 +0200
changeset 7134 320b412e5800
parent 7050 c70d3402fef5
child 7135 8eabfd7e6b9b
permissions -rw-r--r--
more stuff;
     1 
     2 %FIXME
     3 % - examples (!?)
     4 
     5 
     6 \chapter{Isar document syntax}
     7 
     8 FIXME shortcut
     9 
    10 FIXME important note: inner versus outer syntax
    11 
    12 \section{Lexical matters}
    13 
    14 \section{Common syntax entities}
    15 
    16 The Isar proof and theory language syntax has been carefully designed with
    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 
    21 Some of the basic syntactic entities introduced below act much like tokens
    22 rather than nonterminals, in particular for error messages are concerned.
    23 E.g.\ syntax elements such as $\CONSTS$ referring to \railqtoken{name} or
    24 \railqtoken{type} would really report a missing \railqtoken{name} or
    25 \railqtoken{type} rather than any of its constituent primitive tokens
    26 (\railtoken{ident}, \railtoken{string} etc.).
    27 
    28 
    29 \subsection{Names}
    30 
    31 Entity \railqtoken{name} usually refers to any name of types, constants,
    32 theorems, etc.\ to be \emph{declared} or \emph{defined} (so qualified
    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}.
    37 
    38 \indexoutertoken{name}\indexoutertoken{nameref}
    39 \begin{rail}
    40   name : ident | symident | string
    41   ;
    42   nameref : name | longident
    43   ;
    44 \end{rail}
    45 
    46 
    47 \subsection{Comments}
    48 
    49 Large chunks of plain \railqtoken{text} are usually given \railtoken{verbatim},
    50 i.e.\ enclosed in \verb|{*|\dots\verb|*}|.  For convenience, any of the
    51 smaller text entities (\railtoken{ident}, \railtoken{string} etc.)  are
    52 admitted as well.  Almost any of the Isar commands may be annotated by a
    53 marginal \railnonterm{comment}: \texttt{--} \railqtoken{text}.  Note that this
    54 kind of comment is actually part of the language, while source level comments
    55 \verb|(*|\dots\verb|*)| are already stripped at the lexical level.  A few
    56 commands such as $\PROOFNAME$ admit additional markup with a ``level of
    57 interest'', currently only \texttt{\%} for ``boring, don't read this''.
    58 
    59 \indexoutertoken{text}\indexouternonterm{comment}\indexouternonterm{interest}
    60 \begin{rail}
    61   text : verbatim | nameref
    62   ;
    63   comment : '--' text
    64   ;
    65   interest : '\%'
    66   ;
    67 \end{rail}
    68 
    69 
    70 \subsection{Sorts and arities}
    71 
    72 The syntax of sorts and arities is given directly at the outer level.  Note
    73 that this in contrast to that types and terms (see below).  Only few commands
    74 ever refer to sorts or arities explicitly.
    75 
    76 \indexouternonterm{sort}\indexouternonterm{arity}\indexouternonterm{simplearity}
    77 \begin{rail}
    78   sort : nameref | lbrace (nameref * ',') rbrace
    79   ;
    80   arity : ( () | '(' (sort + ',') ')' ) sort
    81   ;
    82   simplearity : ( () | '(' (sort + ',') ')' ) nameref
    83   ;
    84 \end{rail}
    85 
    86 
    87 \subsection{Types and terms}
    88 
    89 The actual inner Isabelle syntax, i.e.\ that of types and terms, is far too
    90 flexible in order to be modeled explicitly at the outer theory level.
    91 Basically, any such entity would have to be quoted at the outer level to turn
    92 it into a single token, with the actual parsing deferred to some functions
    93 that read and type-check terms etc.\ (note that \railqtoken{prop}s will be
    94 handled differently from plain \railqtoken{term}s here).  For convenience, the
    95 quotes may be omitted for any \emph{atomic} term or type (e.g.\ a single
    96 variable).
    97 
    98 \indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
    99 \begin{rail}
   100   type : nameref | typefree | typevar
   101   ;
   102   term : nameref | var | textvar | nat
   103   ;
   104   prop : term
   105   ;
   106 \end{rail}
   107 
   108 Type definitions etc.\ usually refer to \railnonterm{typespec} on the
   109 left-hand side.  This models basic type constructor application at the outer
   110 syntax level.  Note that only plain postfix notation is available here, but no
   111 infixes.
   112 
   113 \indexouternonterm{typespec}
   114 \begin{rail}
   115   typespec : (() | typefree | '(' ( typefree + ',' ) ')') name
   116   ;
   117 \end{rail}
   118 
   119 
   120 \subsection{Term patterns}
   121 
   122 Statements like $\SHOWNAME$ involve propositions, some others like $\DEFNAME$
   123 plain terms.  Any of these usually admit automatic binding of schematic text
   124 variables by giving (optional) patterns $\IS{p@1 \dots p@n}$.  For
   125 \railqtoken{prop}s the $\CONCLNAME$ part refers to the conclusion only, in case
   126 actual rules are involved, rather than atomic propositions.
   127 
   128 \indexouternonterm{termpat}\indexouternonterm{proppat}
   129 \begin{rail}
   130   termpat : '(' (term + 'is' ) ')'
   131   ;
   132   proppat : '(' (() | (prop + 'is' )) (() | 'concl' (prop + 'is' )) ')'
   133   ;
   134 \end{rail}
   135 
   136 
   137 \subsection{Mixfix annotations}
   138 
   139 Mixfix annotations specify concrete \emph{inner} syntax of Isabelle types and
   140 terms.  Some commands such as $\TYPES$ admit infixes only, while $\CONSTS$
   141 etc.\ support the full range of general mixfixes and binders.
   142 
   143 \indexouternonterm{infix}\indexouternonterm{mixfix}
   144 \begin{rail}
   145   infix : '(' ('infixl' | 'infixr') (() | string) nat ')'
   146   ;
   147 
   148   mixfix : infix | string (() | '[' (nat + ',') ']') (() | nat) |
   149   'binder' string (() | '[' (nat + ',') ']') nat
   150   ;
   151 \end{rail}
   152 
   153 
   154 \subsection{Attributes and theorems}\label{sec:syn-att}
   155 
   156 Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
   157 ``semi-inner'' syntax, which does not have to be atomic at the outer level
   158 unlike that of types and terms.  Instead, the attribute argument
   159 specifications may be any sequence of atomic entities (identifiers, strings
   160 etc.), or properly bracketed argument lists.  Below \railqtoken{atom} refers to
   161 any atomic entity (\railtoken{ident}, \railtoken{longident},
   162 \railtoken{symident} etc.), including keywords that conform to
   163 \railtoken{symident}, but do not coincide with actual command names.
   164 
   165 \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
   166 \begin{rail}
   167   atom : nameref | typefree | typevar | var | textvar | nat
   168   ;
   169   arg : atom | '(' args ')' | '[' args ']' | lbrace args rbrace
   170   ;
   171   args : arg *
   172   ;
   173   attributes : '[' (nameref args * ',') ']'
   174   ;
   175 \end{rail}
   176 
   177 Theorem specifications come in three flavors: \railnonterm{thmdecl} usually
   178 refers to the result of an assumption or goal statement (e.g.\ $\SHOWNAME$),
   179 \railnonterm{thmdef} collects lists of existing theorems (as in $\NOTENAME$),
   180 \railnonterm{thmrefs} refers to any list of existing theorems (e.g.\ occurring
   181 as proof method arguments).  Any of these may include lists of attributes,
   182 which are applied to the preceding theorem or list of theorems.
   183 
   184 \indexouternonterm{thmdecl}\indexouternonterm{thmdef}\indexouternonterm{thmrefs}
   185 \begin{rail}
   186   thmname : name attributes | name | attributes
   187   ;
   188   thmdecl : thmname ':'
   189   ;
   190   thmdef : thmname '='
   191   ;
   192   thmrefs : nameref (() | attributes) +
   193   ;
   194 \end{rail}
   195 
   196 
   197 \subsection{Proof methods}\label{sec:syn-meth}
   198 
   199 Proof methods are either basic ones, or expressions composed of methods via
   200 ``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternatives),
   201 ``\texttt{?}'' (try), ``\texttt{*}'' (repeat, ${} \ge 0$ times),
   202 ``\texttt{+}'' (repeat, ${} > 0$ times).  In practice, proof methods are very
   203 often just a comma separated list of \railqtoken{nameref}~\railnonterm{args}
   204 specifications.  Thus the syntax is similar to that of attributes, with plain
   205 parentheses instead of square brackets (see also \S\ref{sec:syn-att}).  Note
   206 that parentheses may be dropped for single method specifications without
   207 arguments.
   208 
   209 \indexouternonterm{method}
   210 \begin{rail}
   211   method : (nameref | '(' methods ')') (() | '?' | '*' | '+')
   212   ;
   213   methods : (nameref args | method) + (',' | '|')
   214   ;
   215 \end{rail}
   216 
   217 
   218 %%% Local Variables: 
   219 %%% mode: latex
   220 %%% TeX-master: "isar-ref"
   221 %%% End: