doc-src/IsarRef/Thy/document/Inner_Syntax.tex
changeset 48113 1c4500446ba4
parent 46525 af3df09590f9
child 48114 428e55887f24
equal deleted inserted replaced
48112:b1240319ef15 48113:1c4500446ba4
    39   the full complexity of inner syntax layers.
    39   the full complexity of inner syntax layers.
    40 
    40 
    41   Further details of the syntax engine involves the classical
    41   Further details of the syntax engine involves the classical
    42   distinction of lexical language versus context-free grammar (see
    42   distinction of lexical language versus context-free grammar (see
    43   \secref{sec:pure-syntax}), and various mechanisms for \emph{syntax
    43   \secref{sec:pure-syntax}), and various mechanisms for \emph{syntax
    44   translations} --- either as rewrite systems on first-order ASTs
    44   transformations} (see \secref{sec:syntax-transformations}).%
    45   (\secref{sec:syn-trans}) or ML functions on ASTs or \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}{\isaliteral{22}{\isachardoublequote}}}-terms that represent parse trees (\secref{sec:tr-funs}).%
       
    46 \end{isamarkuptext}%
    45 \end{isamarkuptext}%
    47 \isamarkuptrue%
    46 \isamarkuptrue%
    48 %
    47 %
    49 \isamarkupsection{Printing logical entities%
    48 \isamarkupsection{Printing logical entities%
    50 }
    49 }
  1183 
  1182 
  1184   \end{description}%
  1183   \end{description}%
  1185 \end{isamarkuptext}%
  1184 \end{isamarkuptext}%
  1186 \isamarkuptrue%
  1185 \isamarkuptrue%
  1187 %
  1186 %
  1188 \isamarkupsection{Raw syntax and translations \label{sec:syn-trans}%
  1187 \isamarkupsection{Syntax transformations \label{sec:syntax-transformations}%
       
  1188 }
       
  1189 \isamarkuptrue%
       
  1190 %
       
  1191 \begin{isamarkuptext}%
       
  1192 The inner syntax engine of Isabelle provides separate
       
  1193   mechanisms to transform parse trees either as rewrite systems on
       
  1194   first-order ASTs (\secref{sec:syn-trans}), or ML functions on ASTs
       
  1195   or syntactic \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}{\isaliteral{22}{\isachardoublequote}}}-terms (\secref{sec:tr-funs}).  This works
       
  1196   both for parsing and printing, as outlined in
       
  1197   \figref{fig:parse-print}.
       
  1198 
       
  1199   \begin{figure}[htbp]
       
  1200   \begin{center}
       
  1201   \begin{tabular}{cl}
       
  1202   string          & \\
       
  1203   \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F776E3E}{\isasymdown}}{\isaliteral{22}{\isachardoublequote}}}     & lexer + parser \\
       
  1204   parse tree      & \\
       
  1205   \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F776E3E}{\isasymdown}}{\isaliteral{22}{\isachardoublequote}}}     & parse AST translation \\
       
  1206   AST             & \\
       
  1207   \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F776E3E}{\isasymdown}}{\isaliteral{22}{\isachardoublequote}}}     & AST rewriting (macros) \\
       
  1208   AST             & \\
       
  1209   \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F776E3E}{\isasymdown}}{\isaliteral{22}{\isachardoublequote}}}     & parse translation \\
       
  1210   --- pre-term ---    & \\
       
  1211   \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F776E3E}{\isasymdown}}{\isaliteral{22}{\isachardoublequote}}}     & print translation \\
       
  1212   AST             & \\
       
  1213   \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F776E3E}{\isasymdown}}{\isaliteral{22}{\isachardoublequote}}}     & AST rewriting (macros) \\
       
  1214   AST             & \\
       
  1215   \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F776E3E}{\isasymdown}}{\isaliteral{22}{\isachardoublequote}}}     & print AST translation \\
       
  1216   string          &
       
  1217   \end{tabular}
       
  1218   \end{center}
       
  1219   \caption{Parsing and printing with translations}\label{fig:parse-print}
       
  1220   \end{figure}
       
  1221 
       
  1222   These intermediate syntax tree formats eventually lead to a pre-term
       
  1223   with all names and binding scopes resolved, but most type
       
  1224   information still missing.  Explicit type constraints might be given by
       
  1225   the user, or implicit position information by the system --- both
       
  1226   needs to be passed-through carefully by syntax transformations.
       
  1227 
       
  1228   Pre-terms are further processed by the so-called \emph{check} and
       
  1229   \emph{unckeck} phases that are intertwined with type-inference (see
       
  1230   also \cite{isabelle-implementation}).  The latter allows to operate
       
  1231   on higher-order abstract syntax with proper binding and type
       
  1232   information already available.
       
  1233 
       
  1234   As a rule of thumb, anything that manipulates bindings of variables
       
  1235   or constants needs to be implemented as syntax transformation (see
       
  1236   below).  Anything else is better done via check/uncheck: a prominent
       
  1237   example application is the \hyperlink{command.abbreviation}{\mbox{\isa{\isacommand{abbreviation}}}} concept of
       
  1238   Isabelle/Pure.%
       
  1239 \end{isamarkuptext}%
       
  1240 \isamarkuptrue%
       
  1241 %
       
  1242 \isamarkupsubsection{Abstract syntax trees%
       
  1243 }
       
  1244 \isamarkuptrue%
       
  1245 %
       
  1246 \begin{isamarkuptext}%
       
  1247 FIXME%
       
  1248 \end{isamarkuptext}%
       
  1249 \isamarkuptrue%
       
  1250 %
       
  1251 \isamarkupsubsection{Raw syntax and translations \label{sec:syn-trans}%
  1189 }
  1252 }
  1190 \isamarkuptrue%
  1253 \isamarkuptrue%
  1191 %
  1254 %
  1192 \begin{isamarkuptext}%
  1255 \begin{isamarkuptext}%
  1193 \begin{matharray}{rcl}
  1256 \begin{matharray}{rcl}
  1372 
  1435 
  1373   \end{itemize}%
  1436   \end{itemize}%
  1374 \end{isamarkuptext}%
  1437 \end{isamarkuptext}%
  1375 \isamarkuptrue%
  1438 \isamarkuptrue%
  1376 %
  1439 %
  1377 \isamarkupsection{Syntax translation functions \label{sec:tr-funs}%
  1440 \isamarkupsubsection{Syntax translation functions \label{sec:tr-funs}%
  1378 }
  1441 }
  1379 \isamarkuptrue%
  1442 \isamarkuptrue%
  1380 %
  1443 %
  1381 \begin{isamarkuptext}%
  1444 \begin{isamarkuptext}%
  1382 \begin{matharray}{rcl}
  1445 \begin{matharray}{rcl}