git @ Cat's Eye Technologies Arboretuum / b170343
Place in public domain. Convert CRLF -> LF in README. catseye 9 years ago
8 changed file(s) with 128 addition(s) and 260 deletion(s). Raw diff Collapse all Expand all
0 The Arboretuum Programming Language
1 ===================================
2
3 March 2008, Chris Pressey, Cat's Eye Technologies.
4
5 Description
6 -----------
7
8 Arboretuum is a language based on an experimental variant of
9 tree-rewriting which we call forest-rewriting. Appropriate to its name,
10 during forest-rewriting, multiple trees (specifically, a finite set) are
11 rewritten. Each tree is labelled with a name; a rewriting pattern can
12 refer to multiple trees, and must match all of them simultaneously in
13 order for a replacement to occur.
14
15 As an experiment, Arboretuum was not entirely a success.
16 Forest-rewriting unfortunately turned out to be insufficient for what I
17 wanted to apply it to, namely compiler specification. The idea was to
18 have each tree associated with some data structure used in the
19 compilation process (AST, symbol table, output buffer, etc.) However, it
20 became apparent that, by itself, forest-rewriting could not synchronize
21 the data across the trees the way it would need to be synchronized in a
22 real compiler. I plan to tackle the problem again, with a different
23 variation on rewriting, in a future project.
24
25 Regardless, Arboretuum is Turing-complete, as tree-rewriting is simply a
26 special case of forest-rewriting: just have one tree in the forest.
27
28 Implementation
29 --------------
30
31 I will refer you to the reference implementation of Arboretuum for
32 details on the semantics of the language. Ordinarily I frown upon this
33 sort of practice — normatively defining a language by an implementation
34 rather than by a specification — but the interests of brevity, the
35 experimental tack of the project, the unsuccessful outcome of the
36 experiment, and the relative well-definedness of the implementation
37 language (the purely functional subset of R5RS Scheme) conspire to
38 make the consequences of this choice less painful than usual.
39
40 The reference implementation comprises the following files:
41
42 - `preprocess.scm`
43
44 Pre-processes the input program into an internal format suitable for
45 forest-rewriting.
46
47 - `unify.scm`
48
49 Implementation of the unification algorithm which is used to match
50 the pattern part of rewriting rules to the forest.
51
52 - `forest-rewrite.scm`
53
54 Implements the forest-rewriting process proper.
55
56 - `utils.scm`
57
58 Miscellanous support procedures, including `mergesort`,
59 `vector-store` (a side-effect-free alternative to `vector-set!`),
60 `print` and `test`.
61
62 In addition, the following supplementary files which are not definitive
63 w.r.t. the Arboretuum language are included in the project:
64
65 - `tests.scm`
66
67 Gives a set of unit tests to confirm the absence of certain
68 erroneous behaviours. (Obviously, no number of unit tests could
69 confirm the absence of *errors*...)
70
71 - `tree-rewrite.scm`
72
73 Some basic tree-rewriting code, to provide contrast between it's
74 complexity and that of forest rewriting.
75
76 Note that the Scheme implementation of algorithms in the above files are
77 to be taken as *pedantic* rather than *efficient*. They are meant to be
78 read (perhaps even enjoyed?) and only incidentally to be executed.
79
80 History
81 -------
82
83 This project was begun in January 2006. I'd been meaning to release it
84 for a while before actually doing so in March of 2008.
85
86 Happy forest-rewriting!
87
88 -Chris Pressey
89 Cat's Eye Technologies
90 March 4, 2008
91 Chicago, Illinois, USA
0 The Arboretuum Programming Language
1 ===================================
2
3 March 2008, Chris Pressey, Cat's Eye Technologies.
4
5 Description
6 -----------
7
8 Arboretuum is a language based on an experimental variant of
9 tree-rewriting which we call forest-rewriting. Appropriate to its name,
10 during forest-rewriting, multiple trees (specifically, a finite set) are
11 rewritten. Each tree is labelled with a name; a rewriting pattern can
12 refer to multiple trees, and must match all of them simultaneously in
13 order for a replacement to occur.
14
15 As an experiment, Arboretuum was not entirely a success.
16 Forest-rewriting unfortunately turned out to be insufficient for what I
17 wanted to apply it to, namely compiler specification. The idea was to
18 have each tree associated with some data structure used in the
19 compilation process (AST, symbol table, output buffer, etc.) However, it
20 became apparent that, by itself, forest-rewriting could not synchronize
21 the data across the trees the way it would need to be synchronized in a
22 real compiler. I plan to tackle the problem again, with a different
23 variation on rewriting, in a future project.
24
25 Regardless, Arboretuum is Turing-complete, as tree-rewriting is simply a
26 special case of forest-rewriting: just have one tree in the forest.
27
28 Implementation
29 --------------
30
31 I will refer you to the reference implementation of Arboretuum for
32 details on the semantics of the language. Ordinarily I frown upon this
33 sort of practice — normatively defining a language by an implementation
34 rather than by a specification — but the interests of brevity, the
35 experimental tack of the project, the unsuccessful outcome of the
36 experiment, and the relative well-definedness of the implementation
37 language (the purely functional subset of R5RS Scheme) conspire to
38 make the consequences of this choice less painful than usual.
39
40 The reference implementation comprises the following files:
41
42 - `preprocess.scm`
43
44 Pre-processes the input program into an internal format suitable for
45 forest-rewriting.
46
47 - `unify.scm`
48
49 Implementation of the unification algorithm which is used to match
50 the pattern part of rewriting rules to the forest.
51
52 - `forest-rewrite.scm`
53
54 Implements the forest-rewriting process proper.
55
56 - `utils.scm`
57
58 Miscellanous support procedures, including `mergesort`,
59 `vector-store` (a side-effect-free alternative to `vector-set!`),
60 `print` and `test`.
61
62 In addition, the following supplementary files which are not definitive
63 w.r.t. the Arboretuum language are included in the project:
64
65 - `tests.scm`
66
67 Gives a set of unit tests to confirm the absence of certain
68 erroneous behaviours. (Obviously, no number of unit tests could
69 confirm the absence of *errors*...)
70
71 - `tree-rewrite.scm`
72
73 Some basic tree-rewriting code, to provide contrast between it's
74 complexity and that of forest rewriting.
75
76 Note that the Scheme implementation of algorithms in the above files are
77 to be taken as *pedantic* rather than *efficient*. They are meant to be
78 read (perhaps even enjoyed?) and only incidentally to be executed.
79
80 History
81 -------
82
83 This project was begun in January 2006. I'd been meaning to release it
84 for a while before actually doing so in March of 2008.
85
86 Happy forest-rewriting!
87
88 -Chris Pressey
89 Cat's Eye Technologies
90 March 4, 2008
91 Chicago, Illinois, USA
0 This is free and unencumbered software released into the public domain.
1
2 Anyone is free to copy, modify, publish, use, compile, sell, or
3 distribute this software, either in source code form or as a compiled
4 binary, for any purpose, commercial or non-commercial, and by any
5 means.
6
7 In jurisdictions that recognize copyright laws, the author or authors
8 of this software dedicate any and all copyright interest in the
9 software to the public domain. We make this dedication for the benefit
10 of the public at large and to the detriment of our heirs and
11 successors. We intend this dedication to be an overt act of
12 relinquishment in perpetuity of all present and future rights to this
13 software under copyright law.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
22
23 For more information, please refer to <http://unlicense.org/>
11 ; Forest Rewriting
22 ; Chris Pressey, late January 2006
33 ;
4
5 ; Copyright (c)2008 Cat's Eye Technologies. All rights reserved.
4 ; This work is in the public domain. See the file UNLICENSE for more
5 ; information.
66 ;
7 ; Redistribution and use in source and binary forms, with or without
8 ; modification, are permitted provided that the following conditions
9 ; are met:
10 ;
11 ; 1. Redistributions of source code must retain the above copyright
12 ; notices, this list of conditions and the following disclaimer.
13 ; 2. Redistributions in binary form must reproduce the above copyright
14 ; notices, this list of conditions, and the following disclaimer in
15 ; the documentation and/or other materials provided with the
16 ; distribution.
17 ; 3. Neither the names of the copyright holders nor the names of their
18 ; contributors may be used to endorse or promote products derived
19 ; from this software without specific prior written permission.
20 ;
21 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
23 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 ; COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 ; POSSIBILITY OF SUCH DAMAGE.
337
348 ;
359 ; Given a term, a pattern to look for in that term, a replacement pattern,
11 ; Preprocessor for Forest Rewriter
22 ; Chris Pressey, sometime late January 2006
33 ;
4
5 ; Copyright (c)2008 Cat's Eye Technologies. All rights reserved.
4 ; This work is in the public domain. See the file UNLICENSE for more
5 ; information.
66 ;
7 ; Redistribution and use in source and binary forms, with or without
8 ; modification, are permitted provided that the following conditions
9 ; are met:
10 ;
11 ; 1. Redistributions of source code must retain the above copyright
12 ; notices, this list of conditions and the following disclaimer.
13 ; 2. Redistributions in binary form must reproduce the above copyright
14 ; notices, this list of conditions, and the following disclaimer in
15 ; the documentation and/or other materials provided with the
16 ; distribution.
17 ; 3. Neither the names of the copyright holders nor the names of their
18 ; contributors may be used to endorse or promote products derived
19 ; from this software without specific prior written permission.
20 ;
21 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
23 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 ; COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 ; POSSIBILITY OF SUCH DAMAGE.
337
348 ;
359 ; The goal here is to allow the compound-rules to be specified in a nicer,
11 ; Test suite for forest-rewriting project
22 ; Chris Pressey, sometime late January 2006
33 ;
4
5 ; Copyright (c)2008 Cat's Eye Technologies. All rights reserved.
4 ; This work is in the public domain. See the file UNLICENSE for more
5 ; information.
66 ;
7 ; Redistribution and use in source and binary forms, with or without
8 ; modification, are permitted provided that the following conditions
9 ; are met:
10 ;
11 ; 1. Redistributions of source code must retain the above copyright
12 ; notices, this list of conditions and the following disclaimer.
13 ; 2. Redistributions in binary form must reproduce the above copyright
14 ; notices, this list of conditions, and the following disclaimer in
15 ; the documentation and/or other materials provided with the
16 ; distribution.
17 ; 3. Neither the names of the copyright holders nor the names of their
18 ; contributors may be used to endorse or promote products derived
19 ; from this software without specific prior written permission.
20 ;
21 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
23 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 ; COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 ; POSSIBILITY OF SUCH DAMAGE.
337
348
359 (load "utils.scm");--------------------------------------------------------
11 ; Bottom-Up Tree-Rewriting (Term-Rewriting)
22 ; Chris Pressey, sometime late January 2006
33 ;
4
5 ; Copyright (c)2008 Cat's Eye Technologies. All rights reserved.
4 ; This work is in the public domain. See the file UNLICENSE for more
5 ; information.
66 ;
7 ; Redistribution and use in source and binary forms, with or without
8 ; modification, are permitted provided that the following conditions
9 ; are met:
10 ;
11 ; 1. Redistributions of source code must retain the above copyright
12 ; notices, this list of conditions and the following disclaimer.
13 ; 2. Redistributions in binary form must reproduce the above copyright
14 ; notices, this list of conditions, and the following disclaimer in
15 ; the documentation and/or other materials provided with the
16 ; distribution.
17 ; 3. Neither the names of the copyright holders nor the names of their
18 ; contributors may be used to endorse or promote products derived
19 ; from this software without specific prior written permission.
20 ;
21 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
23 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 ; COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 ; POSSIBILITY OF SUCH DAMAGE.
337
348 ;
359 ; Try unifying the pattern part of the given rule with the given term;
11 ; Simple support for unification & pattern matching
22 ; Chris Pressey, late January 2006
33 ;
4
5 ; Copyright (c)2008 Cat's Eye Technologies. All rights reserved.
4 ; This work is in the public domain. See the file UNLICENSE for more
5 ; information.
66 ;
7 ; Redistribution and use in source and binary forms, with or without
8 ; modification, are permitted provided that the following conditions
9 ; are met:
10 ;
11 ; 1. Redistributions of source code must retain the above copyright
12 ; notices, this list of conditions and the following disclaimer.
13 ; 2. Redistributions in binary form must reproduce the above copyright
14 ; notices, this list of conditions, and the following disclaimer in
15 ; the documentation and/or other materials provided with the
16 ; distribution.
17 ; 3. Neither the names of the copyright holders nor the names of their
18 ; contributors may be used to endorse or promote products derived
19 ; from this software without specific prior written permission.
20 ;
21 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
23 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 ; COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 ; POSSIBILITY OF SUCH DAMAGE.
337
348 ;
359 ; Return #t if the given pattern is a variable, #f otherwise.
11 ; Utility functions used by forest-rewriting project
22 ; Chris Pressey, late January 2006
33 ;
4
5 ; Copyright (c)2008 Cat's Eye Technologies. All rights reserved.
4 ; This work is in the public domain. See the file UNLICENSE for more
5 ; information.
66 ;
7 ; Redistribution and use in source and binary forms, with or without
8 ; modification, are permitted provided that the following conditions
9 ; are met:
10 ;
11 ; 1. Redistributions of source code must retain the above copyright
12 ; notices, this list of conditions and the following disclaimer.
13 ; 2. Redistributions in binary form must reproduce the above copyright
14 ; notices, this list of conditions, and the following disclaimer in
15 ; the documentation and/or other materials provided with the
16 ; distribution.
17 ; 3. Neither the names of the copyright holders nor the names of their
18 ; contributors may be used to endorse or promote products derived
19 ; from this software without specific prior written permission.
20 ;
21 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
23 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 ; COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 ; POSSIBILITY OF SUCH DAMAGE.
337
348 ;
359 ; Sort a list using mergesort.