doc-src/Ref/theory-syntax.tex
author wenzelm
Tue, 06 May 1997 12:50:16 +0200
changeset 3108 335efc3f5632
parent 3098 a31170b67367
child 3130 1ffe03f4c700
permissions -rw-r--r--
misc updates, tuning, cleanup;
     1 %% $Id$
     2 
     3 \appendix
     4 \newlinechar=-1  %mathsing.sty sets \newlinechar=`\|, which would cause mayhem
     5 
     6 \chapter{Syntax of Isabelle Theories}\label{app:TheorySyntax}
     7 
     8 Below we present the full syntax of theory definition files as
     9 provided by {\Pure} Isabelle --- object-logics may add their own
    10 sections.  \S\ref{sec:ref-defining-theories} explains the meanings of
    11 these constructs.  The syntax obeys the following conventions:
    12 \begin{itemize}
    13 \item {\tt Typewriter font} denotes terminal symbols.
    14   
    15 \item $id$, $tid$, $nat$, $string$ and $longident$ are the lexical
    16   classes of identifiers, type identifiers, natural numbers, quoted
    17   strings (without the need for \verb$\$\dots\verb$\$ between lines)
    18   and long qualified \ML{} identifiers.
    19   The categories $id$, $tid$, $nat$ are fully defined in \iflabelundefined{Defining-Logics}%
    20   {{\it The Isabelle Reference Manual}, chapter `Defining Logics'}%
    21   {\S\ref{Defining-Logics}}.
    22   
    23 \item $text$ is all text from the current position to the end of file,
    24   $verbatim$ is any text enclosed in \verb.{|.\dots\verb.|}.
    25   
    26 \item Comments in theories take the form {\tt (*}\dots{\tt*)} and may
    27   be nested, just as in \ML.
    28 \end{itemize}
    29 
    30 \begin{rail}
    31 
    32 theoryDef : id '=' (name + '+') ('+' extension | ())
    33           ;
    34 
    35 name: id | string
    36     ;
    37 
    38 extension : (section +) 'end' ( () | ml )
    39           ;
    40 
    41 section : classes
    42         | default
    43         | types
    44         | arities
    45         | consts
    46         | syntax
    47         | trans
    48         | defs
    49         | constdefs
    50         | rules
    51         | axclass
    52         | instance
    53         | oracle
    54         ;
    55 
    56 classes : 'classes' ( classDecl + )
    57         ;
    58 
    59 classDecl : (id (() | '<' (id + ',')))
    60         ;
    61 
    62 default : 'default' sort 
    63         ;
    64 
    65 sort :  id
    66      | lbrace (id * ',') rbrace
    67      ;
    68 
    69 types : 'types' ( ( typeDecl ( () | '(' infix ')' ) ) + )
    70       ;
    71 
    72 infix : ( 'infixr' | 'infixl' ) nat
    73       ;
    74 
    75 typeDecl : typevarlist name
    76            ( () | '=' ( string | type ) );
    77 
    78 typevarlist : () | tid | '(' ( tid + ',' ) ')';
    79 
    80 type : simpleType | '(' type ')' | type '=>' type |
    81        '[' ( type + "," ) ']' '=>' type;
    82 
    83 simpleType: id | ( tid ( () | '::' id ) ) |
    84             '(' ( type + "," ) ')' id | simpleType id
    85           ;
    86 
    87 arities : 'arities' ((name + ',') '::' arity +)
    88         ;
    89 
    90 arity : ( () | '(' (sort + ',') ')' ) sort
    91       ;
    92 
    93 consts : 'consts' ( mixfixConstDecl + )
    94        ;
    95 
    96 syntax : 'syntax' (() | mode) ( mixfixConstDecl + );
    97 
    98 mode : '(' name (() | 'output') ')'
    99      ;
   100 
   101 mixfixConstDecl : constDecl (() | ( '(' mixfix ')' ))
   102                 ;
   103 
   104 constDecl : ( name + ',') '::' (string | type);
   105 
   106 mixfix :  string ( () | ( () | ('[' (nat + ',') ']')) nat )
   107        | ( 'infixr' | 'infixl' ) (() | string) nat
   108        | 'binder' string nat ;
   109 
   110 trans : 'translations' ( pat ( '==' | '=>' | '<=' ) pat + )
   111       ;
   112 
   113 pat : ( () | ( '(' id ')' ) ) string;
   114 
   115 rules : 'rules' (( id string ) + )
   116       ;
   117 
   118 defs : 'defs' (( id string ) + )
   119      ;
   120 
   121 constdefs : 'constdefs' (id '::' (string | type) string +)
   122           ;
   123 
   124 axclass : 'axclass' classDecl (() | ( id string ) +)
   125         ;
   126 
   127 instance : 'instance' ( name '<' name | name '::' arity) witness
   128          ;
   129 
   130 witness : (() | ((string | longident) + ',')) (() | verbatim)
   131         ;
   132 
   133 oracle : 'oracle' name
   134        ;
   135 
   136 ml : 'ML' text
   137    ;
   138 
   139 \end{rail}