[Main website]

dok/spec/attribute-grammar

TODO difference between slot and top-down and bottom-up attributes

Attributes depends from the context, i.e. the position of the value respect the Root of the Tree, during the visit function. Root is where I start the visit. In case of parts, the root is the root owner from which I start to navigate for assigning various properties. It can be the DBMS for logical attributes, or the main window for the UI.

Also bottom-up attributes can depend from the visit, because they can depend from top-down attributes. Attr can be seen as a function calculating the result according the cntx-attr implicit params, and the code of this function is derived from the visit.

The values of a slot are associated only to the value and they can be “shared” between different values.

TODO Reference as a closure

A reference to a value of a Tree is:

  • the slot values
  • the top-down attributes
  • the bottom-up attributes depending from other top-dow attributes, otherwise they can be derived from a function on slot

If I take a reference during a visit then the owner of this reference will always remain the original owner, except I make a $ref.copy of the value. In this case the owner become the root of the current visit making this operation, or the object where it is inserted.

TODO rep-min problem

Apparently I had problems with rep-min, in the notes on paper.

I want to rewrite a Tree using the global minimum value of each Leaf.

data Tree::Tree [

  variant ../Node [
    slot left::Self
    slot right::Self
  ]

  variant ../Tip [
    slot value::Int
  ]

  cntx-attr $replacement::Int
  attr transformed::Self

  visit self -when ../Node {
    set self.tranformed self.(with left self.left.~, with right self.right.~)
  } -when ../Tip {
    set self.transformed self.(with value self.$replacement)
  }

  attr min::Int
  attr result::Self

  visit self -when ../Bin {
   set self.min [self.left.min, self.right.min]*.minimum
  } -when ../Leaf {
    set self.min self.value
  }

  cntx-attr $global-min::Int self.min

  fun rep-min::Self {
    return with $replacement self.$global-min { return self.transformed }
  }
]

In a Tree as a value, a part of the Tree is an indipendent value, but its self.$global-min depends from its parent. Hence, or:

  • I admit cntx only for references
  • I manage cntx has a dynamic property linked to the current “execution” function
  • TODO
var tree1::Tree Node(with left Node(with left Tip(3),
                                    with right Tip(10)),
                     with right Tip(2))

var $ref1::$Tree $tree1.left
:^# this is a reference to tree1.left node, having tree1 as root/owner/cntx

var $ref2::$Tree tree1.$left
:^# this is a reference to tree1.left node, having tree1.left as root/owner/cntx

assert {
  test tree1.left.$global-min == 2
  :^# $global-min cntx-attr is propagated from the root to the every node

  test tree1.left.min == 3
  :^# min attribute is relative to the current subtree

  test $ref1.min == $ref2.min == 3
  :^# min attribute is relative to tree1.left, that is the referred value of $ref1 and $ref2

  test $ref1.$global-min == 2
  :^# $global-min is the global mininum of the tree tree1.left having tree1 as root

  test $ref2.$global-min == 3
  :^# $global-min is the global mininum of the tree tree1.left having tree1.left as root

  test $ref1.value.min == $ref.value.min == 3
  test $ref1.value.$global-min == 3
  :^# only tree1.left is copied by "value"

  test $ref2.value.$global-min == 3
  :^# `.value` detach the reference from its previous root,
    #   and now the new root is only `tree1.left`

  test not($ref1 == $ref2)
  :^# they are references to the same value, but with a different root/owner,
    # and potentially different attributes

  test $ref1.value == $ref2.value
  :^# the value is the same, because the slots (but not the attributes) have the same values

}

TODO Examples of RACR

TODO decide the semantic of reference changing

TODO first decide usage example of RACR

TODO Integrate ideas of Nanopass

A language can be described using the differences respect another language.

MAYBE the Dok syntax macro can be used for this.

MAYBE rewrite rules can be used for converting from L1 to L2 when the differences are minimal.

The references can be used, after a rewriting, for mapping the source L1 with the dest L2 of the destination.