2 Author: Markus Wenzel, TU Muenchen |
2 Author: Markus Wenzel, TU Muenchen |
3 |
3 |
4 Abstract syntax trees, translation rules, matching and normalization of asts. |
4 Abstract syntax trees, translation rules, matching and normalization of asts. |
5 *) |
5 *) |
6 |
6 |
7 signature AST0 = |
7 signature AST = |
8 sig |
8 sig |
9 datatype ast = |
9 datatype ast = |
10 Constant of string | |
10 Constant of string | |
11 Variable of string | |
11 Variable of string | |
12 Appl of ast list |
12 Appl of ast list |
|
13 val mk_appl: ast -> ast list -> ast |
13 exception AST of string * ast list |
14 exception AST of string * ast list |
14 end; |
|
15 |
|
16 signature AST1 = |
|
17 sig |
|
18 include AST0 |
|
19 val mk_appl: ast -> ast list -> ast |
|
20 val pretty_ast: ast -> Pretty.T |
15 val pretty_ast: ast -> Pretty.T |
21 val pretty_rule: ast * ast -> Pretty.T |
16 val pretty_rule: ast * ast -> Pretty.T |
|
17 val head_of_rule: ast * ast -> string |
|
18 val rule_error: ast * ast -> string option |
22 val fold_ast: string -> ast list -> ast |
19 val fold_ast: string -> ast list -> ast |
23 val fold_ast_p: string -> ast list * ast -> ast |
20 val fold_ast_p: string -> ast list * ast -> ast |
24 val unfold_ast: string -> ast -> ast list |
21 val unfold_ast: string -> ast -> ast list |
25 val unfold_ast_p: string -> ast -> ast list * ast |
22 val unfold_ast_p: string -> ast -> ast list * ast |
26 val ast_trace_raw: Config.raw |
23 val ast_trace_raw: Config.raw |
27 val ast_trace: bool Config.T |
24 val ast_trace: bool Config.T |
28 val ast_stat_raw: Config.raw |
25 val ast_stat_raw: Config.raw |
29 val ast_stat: bool Config.T |
26 val ast_stat: bool Config.T |
30 end; |
|
31 |
|
32 signature AST = |
|
33 sig |
|
34 include AST1 |
|
35 val head_of_rule: ast * ast -> string |
|
36 val rule_error: ast * ast -> string option |
|
37 val normalize: Proof.context -> (string -> (ast * ast) list) -> ast -> ast |
27 val normalize: Proof.context -> (string -> (ast * ast) list) -> ast -> ast |
38 end; |
28 end; |
39 |
29 |
40 structure Ast : AST = |
30 structure Ast: AST = |
41 struct |
31 struct |
42 |
32 |
43 (** abstract syntax trees **) |
33 (** abstract syntax trees **) |
44 |
34 |
45 (*asts come in two flavours: |
35 (*asts come in two flavours: |
51 datatype ast = |
41 datatype ast = |
52 Constant of string | (*"not", "_abs", "fun"*) |
42 Constant of string | (*"not", "_abs", "fun"*) |
53 Variable of string | (*x, ?x, 'a, ?'a*) |
43 Variable of string | (*x, ?x, 'a, ?'a*) |
54 Appl of ast list; (*(f x y z), ("fun" 'a 'b), ("_abs" x t)*) |
44 Appl of ast list; (*(f x y z), ("fun" 'a 'b), ("_abs" x t)*) |
55 |
45 |
56 |
|
57 (*the list of subasts of an Appl node has to contain at least 2 elements, i.e. |
46 (*the list of subasts of an Appl node has to contain at least 2 elements, i.e. |
58 there are no empty asts or nullary applications; use mk_appl for convenience*) |
47 there are no empty asts or nullary applications; use mk_appl for convenience*) |
59 |
|
60 fun mk_appl f [] = f |
48 fun mk_appl f [] = f |
61 | mk_appl f args = Appl (f :: args); |
49 | mk_appl f args = Appl (f :: args); |
62 |
50 |
63 |
|
64 (*exception for system errors involving asts*) |
51 (*exception for system errors involving asts*) |
65 |
|
66 exception AST of string * ast list; |
52 exception AST of string * ast list; |
67 |
53 |
68 |
54 |
69 |
55 |
70 (** print asts in a LISP-like style **) |
56 (** print asts in a LISP-like style **) |