In This Article

AST Nodes Configuration Pane

The AST Nodes configuration pane is used to design the type-specific AST node classes 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 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.

Pane Layout

The AST Nodes configuration pane contains two lists, one above the other. The upper list displays the AST node classes 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, 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 already defined for the language.

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 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 property type 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 strings, ints, bools, enums, and flags enums.
  • SimpleList – Gets an IList containing a collection of strings, ints, bools, or enums.
  • AstNode – Gets or sets an AST node object.
  • AstNodeList – Gets an IList 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.

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.