- Specify and generate AST node class
- Map and automatically intialize AST node's fields
We start with current rule syntax:
AddOpNode Add := Value "+" Value;
We will need manually initialize an AddOpNode
instance:
class AddOpNode : AstNode
{
public ValueNode X;
public ValueNode Y;
public void Init(AstContext context, ParseTreeNode node)
{
var children = node.getMappedChildren();
X = (ValueNode)AddChild("x", node[0]);
Y = (ValueNode)AddChild("x", node[2]);
}
}
How about a syntax that does it all:
ValueNode Value := ID | STRING; // ID and STRING are terminals
AddOpNode Add := Value->.X "+" Value->.Y;
List initialization:
ValueListNode ValueList := Value{","}->.[];
Terminals should be considered as atom. So it is unlikely a good practice to have fields within. (TBD)