(Context ctx)
| 1716 | // / tree ::= nil | cons(forest, forest) |
| 1717 | // / </remarks> |
| 1718 | public void forestExample(Context ctx) throws TestFailedException |
| 1719 | { |
| 1720 | System.out.println("ForestExample"); |
| 1721 | Log.append("ForestExample"); |
| 1722 | |
| 1723 | Sort tree, forest; |
| 1724 | @SuppressWarnings("unused") |
| 1725 | FuncDecl nil1_decl, is_nil1_decl, cons1_decl, is_cons1_decl, car1_decl, cdr1_decl; |
| 1726 | @SuppressWarnings("unused") |
| 1727 | FuncDecl nil2_decl, is_nil2_decl, cons2_decl, is_cons2_decl, car2_decl, cdr2_decl; |
| 1728 | @SuppressWarnings("unused") |
| 1729 | Expr nil1, nil2, t1, t2, t3, t4, f1, f2, f3, l1, l2, x, y, u, v; |
| 1730 | |
| 1731 | // |
| 1732 | // Declare the names of the accessors for cons. |
| 1733 | // Then declare the sorts of the accessors. |
| 1734 | // For this example, all sorts refer to the new types 'forest' and |
| 1735 | // 'tree' |
| 1736 | // being declared, so we pass in null for both sorts1 and sorts2. |
| 1737 | // On the other hand, the sort_refs arrays contain the indices of the |
| 1738 | // two new sorts being declared. The first element in sort1_refs |
| 1739 | // points to 'tree', which has index 1, the second element in sort1_refs |
| 1740 | // array |
| 1741 | // points to 'forest', which has index 0. |
| 1742 | // |
| 1743 | Symbol[] head_tail1 = new Symbol[] { ctx.mkSymbol("head"), |
| 1744 | ctx.mkSymbol("tail") }; |
| 1745 | Sort[] sorts1 = new Sort[] { null, null }; |
| 1746 | int[] sort1_refs = new int[] { 1, 0 }; // the first item points to a |
| 1747 | // tree, the second to a forest |
| 1748 | |
| 1749 | Symbol[] head_tail2 = new Symbol[] { ctx.mkSymbol("car"), |
| 1750 | ctx.mkSymbol("cdr") }; |
| 1751 | Sort[] sorts2 = new Sort[] { null, null }; |
| 1752 | int[] sort2_refs = new int[] { 0, 0 }; // both items point to the forest |
| 1753 | // datatype. |
| 1754 | Constructor nil1_con, cons1_con, nil2_con, cons2_con; |
| 1755 | Constructor[] constructors1 = new Constructor[2], constructors2 = new Constructor[2]; |
| 1756 | Symbol[] sort_names = { ctx.mkSymbol("forest"), ctx.mkSymbol("tree") }; |
| 1757 | |
| 1758 | /* build a forest */ |
| 1759 | nil1_con = ctx.mkConstructor(ctx.mkSymbol("nil"), |
| 1760 | ctx.mkSymbol("is_nil"), null, null, null); |
| 1761 | cons1_con = ctx.mkConstructor(ctx.mkSymbol("cons1"), |
| 1762 | ctx.mkSymbol("is_cons1"), head_tail1, sorts1, sort1_refs); |
| 1763 | constructors1[0] = nil1_con; |
| 1764 | constructors1[1] = cons1_con; |
| 1765 | |
| 1766 | /* build a tree */ |
| 1767 | nil2_con = ctx.mkConstructor(ctx.mkSymbol("nil2"), |
| 1768 | ctx.mkSymbol("is_nil2"), null, null, null); |
| 1769 | cons2_con = ctx.mkConstructor(ctx.mkSymbol("cons2"), |
| 1770 | ctx.mkSymbol("is_cons2"), head_tail2, sorts2, sort2_refs); |
| 1771 | constructors2[0] = nil2_con; |
| 1772 | constructors2[1] = cons2_con; |
| 1773 | |
| 1774 | Constructor[][] clists = new Constructor[][] { constructors1, |
| 1775 | constructors2 }; |
no test coverage detected