swp-uebersetzerbau-ss13 / common

Shared files between teams.
1 stars 0 forks source link

Token - ASTNode relationship #27

Closed Tkrauss closed 11 years ago

Tkrauss commented 11 years ago

We need the support to associate tokens with an ASTNode for the purpose of debugging. I propose two alternatives, each associated with one method of the ASTNode Option 1:

// this method returns a interval-like object. This means, every token between the token tuple.left and the token tuple.right ( both inclusive) is in this subtree.
Tuple<Token,Token> coverage()

Option 2:

// this method returns the list of tokens, whose are covered within this ast-node ( and its complete subtree). 
// node1.coverage() is real subset of node2.coverage() <=> node1 is in subtree of node2
// Plus, the returned list must be ordered in a left-to-right-fashion.
List<Token> coverage()

I prefer option 2, since it is easy implementable using the current iterator ( at least, in the javabite-implementation) and ther's no need for more classes. What do you think?

leinge commented 11 years ago

I'd prefer the option 2, too! But I can't see why one node should hold all the tokens of its subtree. This seems very redundant to me, and I can't imagine a situation where this would be necessary atm...?

Tkrauss commented 11 years ago

In theory, this would be the choice of the implementation. Since we need this method only if something went wrong and additional just for a (probably small) subtree of the whole AST is the subject, there's no need to hold the value in each node in every situation. I would prefer an ad-hoc computation, but -- like i already said -- this is a matter of the implementation.

Tkrauss commented 11 years ago

So... if there are no more pleas, i'll define the interface as it was described (option 2) at 8pm today.