doc-src/IsarRef/syntax.tex
author wenzelm
Tue, 03 Aug 1999 18:56:51 +0200
changeset 7167 0b2e3ef1d8f4
parent 7141 a67dde8820c0
child 7175 8263d0b50e12
permissions -rw-r--r--
tuned;
much more material;
     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 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.
    23 E.g.\ syntax elements such as $\CONSTS$ referring to \railqtoken{name} or
    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}.
    27 
    28 
    29 \subsection{Names}
    30 
    31 Entity \railqtoken{name} usually refers to any name of types, constants,
    32 theorems etc.\ that are 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{parname}\indexoutertoken{nameref}
    39 \begin{rail}
    40   name: ident | symident | string
    41   ;
    42   parname: '(' name ')'
    43   ;
    44   nameref: name | longident
    45   ;
    46 \end{rail}
    47 
    48 
    49 \subsection{Comments}
    50 
    51 Large chunks of plain \railqtoken{text} are usually given
    52 \railtoken{verbatim}, i.e.\ enclosed in \verb|{*|\dots\verb|*}|.  For
    53 convenience, any of the smaller text conforming to \railqtoken{nameref} are
    54 admitted as well.  Almost any of the Isar commands may be annotated by some
    55 marginal \railnonterm{comment} of the form \texttt{--} \railqtoken{text}.
    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.
    63 
    64 \indexoutertoken{text}\indexouternonterm{comment}\indexouternonterm{interest}
    65 \begin{rail}
    66   text: verbatim | nameref
    67   ;
    68   comment: '--' text
    69   ;
    70   interest: percent nat? | ppercent
    71   ;
    72 \end{rail}
    73 
    74 
    75 \subsection{Sorts and arities}
    76 
    77 The syntax of sorts and arities is given directly at the outer level.  Note
    78 that this is in contrast to that types and terms (see \ref{sec:types-terms}).
    79 
    80 \indexouternonterm{sort}\indexouternonterm{arity}\indexouternonterm{simplearity}
    81 \indexouternonterm{classdecl}
    82 \begin{rail}
    83   classdecl: name ('<' (nameref ',' +))?
    84   ;
    85   sort: nameref | lbrace (nameref * ',') rbrace
    86   ;
    87   arity: ('(' (sort + ',') ')')? sort
    88   ;
    89   simplearity: ('(' (sort + ',') ')')? nameref
    90   ;
    91 \end{rail}
    92 
    93 
    94 \subsection{Types and terms}\label{sec:types-terms}
    95 
    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
    99 a single token, with the actual parsing deferred to some functions for reading
   100 and type-checking.  For convenience, a more liberal convention is adopted:
   101 quotes may be omitted for any type or term that is already \emph{atomic} at
   102 the outer level.  E.g.\ one may write \texttt{x} instead of \texttt{"x"}.
   103 
   104 \indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
   105 \begin{rail}
   106   type: nameref | typefree | typevar
   107   ;
   108   term: nameref | var | textvar | nat
   109   ;
   110   prop: term
   111   ;
   112 \end{rail}
   113 
   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.
   118 
   119 \indexouternonterm{typespec}
   120 \begin{rail}
   121   typespec: (() | typefree | '(' ( typefree + ',' ) ')') name
   122   ;
   123 \end{rail}
   124 
   125 
   126 \subsection{Term patterns}
   127 
   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.
   133 
   134 \indexouternonterm{termpat}\indexouternonterm{proppat}
   135 \begin{rail}
   136   termpat: '(' ('is' term +) ')'
   137   ;
   138   proppat: '(' (('is' prop +) | 'concl' ('is' prop +) | ('is' prop +) 'concl' ('is' prop +)) ')'
   139   ;
   140 \end{rail}
   141 
   142 
   143 \subsection{Mixfix annotations}
   144 
   145 Mixfix annotations specify concrete \emph{inner} syntax of Isabelle types and
   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.
   148 
   149 \indexouternonterm{infix}\indexouternonterm{mixfix}
   150 \begin{rail}
   151   infix: '(' ('infixl' | 'infixr') string? nat ')'
   152   ;
   153   mixfix: infix | '(' string pris? nat? ')' | '(' 'binder' string pris? nat ')'
   154   ;
   155 
   156   pris: '[' (nat + ',') ']'
   157   ;
   158 \end{rail}
   159 
   160 
   161 \subsection{Attributes and theorems}\label{sec:syn-att}
   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
   167 etc.), or properly bracketed argument lists.  Below \railqtoken{atom} refers
   168 to any atomic entity, including keywords that conform to \railtoken{symident}.
   169 
   170 \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
   171 \begin{rail}
   172   atom: nameref | typefree | typevar | var | textvar | nat | keyword
   173   ;
   174   arg: atom | '(' args ')' | '[' args ']' | lbrace args rbrace
   175   ;
   176   args: arg *
   177   ;
   178   attributes: '[' (nameref args * ',') ']'
   179   ;
   180 \end{rail}
   181 
   182 Theorem specifications come in several flavors: \railnonterm{axmdecl} and
   183 \railnonterm{thmdecl} usually refer to assumptions or results of goal
   184 statements, \railnonterm{thmdef} collects lists of existing theorems,
   185 \railnonterm{thmrefs} refers to any lists of existing theorems.  Any of these
   186 may include lists of attributes, which are applied to the preceding theorem or
   187 list of theorems.
   188 
   189 \indexouternonterm{thmdecl}\indexouternonterm{axmdecl}
   190 \indexouternonterm{thmdef}\indexouternonterm{thmrefs}
   191 \begin{rail}
   192   axmdecl: name attributes? ':'
   193   ;
   194   thmdecl: thmname ':'
   195   ;
   196   thmdef: thmname '='
   197   ;
   198   thmrefs: nameref attributes? +
   199   ;
   200 
   201   thmname: name attributes | name | attributes
   202   ;
   203 \end{rail}
   204 
   205 
   206 \subsection{Proof methods}\label{sec:syn-meth}
   207 
   208 Proof methods are either basic ones, or expressions composed of methods via
   209 ``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternatives),
   210 ``\texttt{?}'' (try), ``\texttt{*}'' (repeat ${} \ge 0$ times), ``\texttt{+}''
   211 (repeat ${} > 0$ times).  In practice, proof methods are usually just a comma
   212 separated list of \railqtoken{nameref}~\railnonterm{args} specifications.
   213 Thus the syntax is similar to that of attributes, with plain parentheses
   214 instead of square brackets (see also \S\ref{sec:syn-att}).  Note that
   215 parentheses may be dropped for single method specifications without arguments.
   216 
   217 \indexouternonterm{method}
   218 \begin{rail}
   219   method: (nameref | '(' methods ')') (() | '?' | '*' | '+')
   220   ;
   221   methods: (nameref args | method) + (',' | '|')
   222   ;
   223 \end{rail}
   224 
   225 
   226 %%% Local Variables: 
   227 %%% mode: latex
   228 %%% TeX-master: "isar-ref"
   229 %%% End: