ThomasH
ThomasH

Reputation: 23506

Rascal: What is the difference between "label" and "name" in the Syntax Definition documentation?

The SyntaxDefinition documentation page of Rascal has two sections, where one speaks about "labels" (starting with "Each alternative of a syntax definition is defined by a list of Symbols."), the other about "names" (starting with "Alternatives can be named or not."). For both items a list of effects are given that largely overlap, e.g. both enable the is operator, are necessary for imploding ParseTrees or for writing Action functions. The Syntax section at the top of the page only lists a Name component, and Tags but no labels.

Is "label" an alternative term for "name"? And if so why do the lists of the effects using them differ?

Upvotes: 1

Views: 153

Answers (1)

Jurgen Vinju
Jurgen Vinju

Reputation: 6696

That documentation page could use some love indeed.

The "labels" that are talked about function as optionally declared "names" for two different kinds of things:

  1. alternative rules of a non-terminal may have a label, as in syntax E = add: E "+" E | sub: E "-" E;
  2. symbol positions inside a syntax rule may have a label, as in syntax E = E lhs "+" E rhs | E lhs "-" E rhs;

Having a label on a rule enables different functionality from having a label on a symbol position.

For rules we get:

  • myExp is myLabel ; checks to see if the top parse tree node has a syntax rule labeled with that label
  • ParseTree::implode uses the rule labels to map concrete parse tree nodes to abstract data tree nodes
  • When writing a post-parse disambiguation filter, an Action filter, you must use the alternative name to bind the filter to the proper parsetree node, as in Exp add(Exp lhs, Exp rhs) { ... } will be called when constructing syntax Exp = add: Exp "+" Exp;

For symbol positions we get:

  • myExp has myLabel; checks to see whether the current parse tree node has a syntax rule where one of the symbol positions is labeled with myLabel
  • myExp.myLabel; projects out the tree at the labeled position from given parse tree
  • myExp.myLabel = newExp; replaces the tree at the labeled position in the given parse tree

Upvotes: 1

Related Questions