In This Article

AST Nodes Configuration Pane

The AST Nodes configuration pane is used to design the type-specific abstract syntax tree (AST) node classes and interfaces that can be code generated by the Language Designer, and used with the LL(*) Parser Framework.

Type-specific AST nodes, described in more detail in the general AST nodes topic, are distinct classes and/or interfaces designed to represent each type of AST node that a language grammar can create. The features described in this topic make it easy to configure type-specific AST nodes for a language grammar, and fully code generate those node classes/interfaces.

Pane Layout

The AST Nodes configuration pane contains two lists, one above the other. The upper list displays the AST node classes/interfaces defined for the language, which can be code generated. The lower list displays the properties that will be code generated for the selected AST node in the upper list.

The Properties tool window is heavily used with this pane since it allows for the changing of configuration settings for the nodes and their properties. Whichever list was focused last is the one that the Properties tool window considers active.

Note that multiple items can be selected in either list, and the Properties window allows you to change common values among all the selected instances. This is useful when changing the base type of multiple AST nodes, etc.

AST Node Configuration

AST node configuration is done by modifying items in the upper list.

Adding AST Nodes

To add AST nodes, make sure the upper list has focus then click the Add button in the ribbon. A dialog will appear asking you for the keys of the new AST nodes. Enter one key per line, where each key conforms to standard identifier syntax since they will be used as the class name in code generation. A new AST node is created for each key that you enter.

For instance, if you are building a set of expression-related AST nodes for a syntax language, you might start with adding an Expression base AST node. Then add other AST nodes with keys like LiteralExpression, ParenthesizedExpression, UnaryExpression, and so on and set each of their Inherits values to be the base Expression AST node. That way, any productions in your grammar that deal with general expressions can return an AST node of type Expression and any of the expression implementation AST node types can be returned since they inherit Expression.

Updating AST Nodes

Select one or more AST nodes in the upper list and use the Properties tool window to modify their properties. You can double-click an AST node in the list to open the Properties tool window.

A Description is a text description of the node, used in code generation comments.

The Inherits property indicates the base class for the AST node. If left blank, the default AST node base class will be used. A drop-down is provided, allowing for quick selection of any AST node classes already defined for the language. This property is ignored by interface AST nodes, as they cannot inherit a base class.

The Implements property indicates the interfaces optionally implemented by the AST node. A drop-down is provided, allowing for quick selection of any AST node interfaces already defined for the language. If multiple interfaces are implemented, separate the names with commas.

The Kind property specifies whether the AST node is a class or interface.

Removing AST Nodes

AST nodes can be removed by either selecting the items in the upper list and clicking the ribbon's Remove button (after focusing the list), or by clicking the ribbon's Clear button, which will remove all of them.

AST Node Property Configuration

AST node property configuration is done by modifying items in the lower list. The lower list displays the properties to code generate for the selected AST node in the upper list.

Adding Properties

To add properties, first select the target AST node in the upper list, then click the lower list to focus it, and finally click the Add button in the ribbon. A dialog will appear asking you for the keys of the new properties. Enter one key per line, where each key conforms to standard identifier syntax since they will be used as the property name in code generation. A new property is created for each key that you enter.

For instance, a ParenthesizedExpression AST node would likely need a property named ChildExpression added, which would be an AstNode property type, and its Type would be Expression.

Updating Properties

Select one or more properties in the lower list and use the Properties tool window to modify their properties. You can double-click a property in the list to open the Properties tool window.

A Description is a text description of the property, used in code generation comments.

The PropertyType property indicates the kind of property to generate, which is one of these options:

  • Simple – Gets or sets a simple CLR type object. Supported types are String, Int32, Boolean, and Enum.
  • SimpleList – Gets an IList<T> containing a collection of String, Int32, Boolean, or Enum.
  • AstNode – Gets or sets an AST node object.
  • AstNodeList – Gets an IList<T> containing a collection of AST nodes.

The property types that relate to child AST nodes are separated out since code generation will add special code to generated AST node classes to allow those to be enumerated through as child nodes. To define an Enum as the Type for Simple or SimpleList, enter the name directly in the property grid as enumeration names will not be listed in the drop-down.

The Type property specifies the Type returned by the property, which can be an AST node type name, a String, etc.

Removing Properties

Properties can be removed by either selecting the items in the lower list and clicking the ribbon's Remove button (after focusing the list), or by clicking the ribbon's Clear button, which will remove all of them.

Code Generation

Any AST nodes defined in this pane will show in the list of files that can be code generated.

The generated classes for AST nodes fully implement IAstNode and can be used with the LL(*) Parser Framework's tree construction mechanism.

The classes are output with a partial modifier so that they can be extended as needed with other partial classes in the same project.