22 the full complexity of inner syntax layers. |
22 the full complexity of inner syntax layers. |
23 |
23 |
24 Further details of the syntax engine involves the classical |
24 Further details of the syntax engine involves the classical |
25 distinction of lexical language versus context-free grammar (see |
25 distinction of lexical language versus context-free grammar (see |
26 \secref{sec:pure-syntax}), and various mechanisms for \emph{syntax |
26 \secref{sec:pure-syntax}), and various mechanisms for \emph{syntax |
27 translations} --- either as rewrite systems on first-order ASTs |
27 transformations} (see \secref{sec:syntax-transformations}). |
28 (\secref{sec:syn-trans}) or ML functions on ASTs or @{text |
|
29 "\<lambda>"}-terms that represent parse trees (\secref{sec:tr-funs}). |
|
30 *} |
28 *} |
31 |
29 |
32 |
30 |
33 section {* Printing logical entities *} |
31 section {* Printing logical entities *} |
34 |
32 |
1009 |
1007 |
1010 \end{description} |
1008 \end{description} |
1011 *} |
1009 *} |
1012 |
1010 |
1013 |
1011 |
1014 section {* Raw syntax and translations \label{sec:syn-trans} *} |
1012 section {* Syntax transformations \label{sec:syntax-transformations} *} |
|
1013 |
|
1014 text {* The inner syntax engine of Isabelle provides separate |
|
1015 mechanisms to transform parse trees either as rewrite systems on |
|
1016 first-order ASTs (\secref{sec:syn-trans}), or ML functions on ASTs |
|
1017 or syntactic @{text "\<lambda>"}-terms (\secref{sec:tr-funs}). This works |
|
1018 both for parsing and printing, as outlined in |
|
1019 \figref{fig:parse-print}. |
|
1020 |
|
1021 \begin{figure}[htbp] |
|
1022 \begin{center} |
|
1023 \begin{tabular}{cl} |
|
1024 string & \\ |
|
1025 @{text "\<down>"} & lexer + parser \\ |
|
1026 parse tree & \\ |
|
1027 @{text "\<down>"} & parse AST translation \\ |
|
1028 AST & \\ |
|
1029 @{text "\<down>"} & AST rewriting (macros) \\ |
|
1030 AST & \\ |
|
1031 @{text "\<down>"} & parse translation \\ |
|
1032 --- pre-term --- & \\ |
|
1033 @{text "\<down>"} & print translation \\ |
|
1034 AST & \\ |
|
1035 @{text "\<down>"} & AST rewriting (macros) \\ |
|
1036 AST & \\ |
|
1037 @{text "\<down>"} & print AST translation \\ |
|
1038 string & |
|
1039 \end{tabular} |
|
1040 \end{center} |
|
1041 \caption{Parsing and printing with translations}\label{fig:parse-print} |
|
1042 \end{figure} |
|
1043 |
|
1044 These intermediate syntax tree formats eventually lead to a pre-term |
|
1045 with all names and binding scopes resolved, but most type |
|
1046 information still missing. Explicit type constraints might be given by |
|
1047 the user, or implicit position information by the system --- both |
|
1048 needs to be passed-through carefully by syntax transformations. |
|
1049 |
|
1050 Pre-terms are further processed by the so-called \emph{check} and |
|
1051 \emph{unckeck} phases that are intertwined with type-inference (see |
|
1052 also \cite{isabelle-implementation}). The latter allows to operate |
|
1053 on higher-order abstract syntax with proper binding and type |
|
1054 information already available. |
|
1055 |
|
1056 As a rule of thumb, anything that manipulates bindings of variables |
|
1057 or constants needs to be implemented as syntax transformation (see |
|
1058 below). Anything else is better done via check/uncheck: a prominent |
|
1059 example application is the @{command abbreviation} concept of |
|
1060 Isabelle/Pure. *} |
|
1061 |
|
1062 |
|
1063 subsection {* Abstract syntax trees *} |
|
1064 |
|
1065 text {* |
|
1066 FIXME |
|
1067 *} |
|
1068 |
|
1069 |
|
1070 subsection {* Raw syntax and translations \label{sec:syn-trans} *} |
1015 |
1071 |
1016 text {* |
1072 text {* |
1017 \begin{matharray}{rcl} |
1073 \begin{matharray}{rcl} |
1018 @{command_def "nonterminal"} & : & @{text "theory \<rightarrow> theory"} \\ |
1074 @{command_def "nonterminal"} & : & @{text "theory \<rightarrow> theory"} \\ |
1019 @{command_def "syntax"} & : & @{text "theory \<rightarrow> theory"} \\ |
1075 @{command_def "syntax"} & : & @{text "theory \<rightarrow> theory"} \\ |