Tweets by @Actipro
Please take some time to learn more about us and our product offerings.
This post continues our series on new features coming to SyntaxEditor 2011.1, primarily centered around our LL(*) Parser Framework.
In our last post, we discussed how our goal for enhancements was to add support for the creation of type-specific AST nodes in our parser grammars. This means that instead of always creating default generic AST node instances, we’d be creating different AST node class instances based on context.
In today’s post, we’re going to look at new features added to our Language Designer application which focus on AST node code generation.
Before we get into the AST node code generation features, one new feature added to the Language Designer is the ability to select which parser to debug when loading an assembly that has more than one parser defined in it. In the past, the first parser found would be used.
Now, if more than one parser is defined in an assembly when going to debug a grammar, it will prompt you for which parser to select.
As mentioned before, 2011.1 adds support for type-specific AST nodes. We’ll get into how to create them in the grammar in our next post. But before we get to that, let’s first show how to create the AST node classes.
All AST nodes need to implement the IAstNode interface. We’ve added a new AstNodeBase class that implements IAstNode and is intended to be used as the base class for type-specific AST node classes.
Even with that, hand-writing type-specific AST node classes is a tedious task. For instance in our .NET Languages Add-on that is in development, we have over 130 AST node classes. We certainly don’t want to write that many classes by hand. So what we’ve come up with is additions to the Language Designer that make it easy to design your AST node classes and have it code generate them for you.
When you run the 2011.1 version Language Designer, you’ll notice a new AST Nodes button at the top. That opens the pane that allows you to design your AST nodes.
In the screenshot below you can see that the AssignmentExpression node is selected. The property grid control on the right allows us to alter the properties of the selected node(s).
Now let’s click on one of the AST node properties for the selected node in the bottom list on the left.
Notice how the property grid now shows properties of the selected AST node property. In this case, information for the OperatorType property is displayed.
There are four AST node property types:
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.
Now lets click the Configuration button.
You’ll note that there are a number of AST node classes listed in the files that we can code generate. In 2011.1, all code generated C# and VB files now have a .g in their filenames to mark them as generated files.
If we double-click a file in the list, we can see what will be code generated:
In the above screenshot, I opened the CastExpression code. While we can’t see the entire list of members that is generated from this screenshot, it has properties that wrap the fields displayed there, along with other members that help implement the IAstNode interface.
An important thing to note is that all AST node classes are generated as partial classes. This allows you to create your own CastExpression.cs in the same project that adds other members to the class. You may wish to override ToString or add other helper methods. The ability to totally customize everything is a key feature of this design.
Today’s post showed how the 2011.1 Language Designer makes it easy to code generate AST node classes. You simply set a few properties and everything is done for you.
Now that we have a full array of type-specific AST nodes defined, in the next post we’ll examine the grammar enhancements that allow us to create these nodes while parsing and set their properties.
January 17, 2011 at 01:48
SyntaxEditor 2011.1 Updates Part 2: New Language Designer Features
You've been kicked (a good thing) - Trackback from DotNetKicks.com
April 7, 2011 at 10:21
Actipro Blog 2011 Q1 Posting Summary
Actipro Blog 2011 Q1 Posting Summary
The Actipro Blog - WPF, Silverlight, and WinForms Development