开发者

Stratego/XT: Understanding the basic of basics

I have really tried to get my head around the firs开发者_StackOverflow中文版t steps of understanding Stratego/XT. I've googled a lot and all the web resources I have found seem to make a large enough leap at the beginning that I just can't make the connection. Let me explain.

I understand Abstract Syntax Trees like this:

Minus(Call(Var("f"),[Plus(Var("a"),Int("10"))]),Int("3"))

But then it seems (in the very next sentence even) the documents make this leap to this:

LetSplit :
  Let([d1, d2 | d*], e*) ->
  Let([d1], Let([d2 | d*], e*))

This makes no sense to me. Could someone explain what is going on here with LetSplit?

Also, is there a good resource for furthering a solid understanding of Stratego/XT that is easier to read that the garganutan and complex official "tutorial" on the Stratego/XT website?

Thanks!


LetSplit :
  Let([d1, d2 | d*], e*) ->
  Let([d1], Let([d2 | d*], e*))

This is a rewrite rule with the name LetSplit.

It is equivalent (syntactic sugar) to the strategy:

LetSplit =
  ?Let([d1, d2 | d*], e*) ;        // match
  !Let([d1], Let([d2 | d*], e*))   // build

When invoked, then, when the left hand side Let([d1, d2 | d*], e*) (the match part) matches the current term, the current term is replaced by the right hand side Let([d1], Let([d2 | d*], e*)) (the build part). When the left hand side does not match, the rule fails and the current term remains unchanged.

d1, d2, d*, e* are term variables bound to the sub-terms found at their respective positions during the match. The names are then used in the build part, where they expand to the sub-tree they were bound to before. Note that indeed, * and ' may appear at the end of term variable names. The single quote has no special meaning, while * has a special meaning in list build operations (not the case here).

The syntax [d1, d2 | d*] in the match part matches any list with at least two elements. These elements will be bound to d1 and d2 and the remaining elements in the list will be bound to d* (so d* will be a list, and may be the empty list []).

Also, is there a good resource for furthering a solid understanding of Stratego/XT that is easier to read that the garganutan and complex official "tutorial" on the Stratego/XT website?

Research papers. Though admittedly they aren't really easier to read, but arguably they are the only place where some of the more advanced concepts are explained.

  • Stratego/XT 0.17. A language and toolset for program transformation (may be a good starting point to find keywords to use in e.g. google scholar)
  • Program Transformation with Scoped Dynamic Rewrite Rules (scary, but contains a wealth of information about dynamic rewrite rules that is hard to find elsewhere)
  • more papers

Anyway feel free to ask more questions here on stackoverflow, I will try to answer them :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜