Parser generator AstNode inheritance

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by David Chang - Software Engineer, a.i. solutions, Inc.
Avatar
Hi,

I am using Parser generator to create a parser for our product.

In it we have several flavor of variable declaration statement.

To make sure we don't carry too much information, I created the most general variable declaration statement class and have the more specific ones subclass from that.

So we have the following definition:

            <AstNode Name="Statement" IsAbstract="true" Description="The base class for a statement." />

            <AstNode Name="VariableDeclarationStatement" Inherits="Statement" Description="A variable declaration statement.">
                <AstNodeProperty PropertyType="AstNode" Name="Type" Type="ObjectType" Description="The object type." />
                <AstNodeProperty PropertyType="AstNode" Name="Name" Type="Identifier" Description="The object name." />
                <AstNodeProperty PropertyType="Simple" Name="IsGlobal" Type="bool" Description="Is the object global?" />
                <AstNodeDeclarations Type="Constructor"><![CDATA[    

                    /// <summary>
                    /// Initializes a new instance of the <c>VariableDeclarationStatement</c> class. 
                    /// </summary>
                    /// <param name="objectType">The object type.</param>
                    /// <param name="objectName">The text of the qualified identifier.</param>
                    /// <param name="isGlobal">Is the object global?</param>
                    /// <param name="textRange">The <see cref="TextRange"/> of the AST node.</param>
                    public VariableDeclarationStatement(ObjectType objectType, Identifier objectName, bool isGlobal, TextRange textRange) : this(textRange) {
                        // Initialize parameters
                        this.Type = objectType;
                        this.Name = objectName;
                        this.IsGlobal = isGlobal;
                    }

                ]]></AstNodeDeclarations>
                <AstNodeDeclarations><![CDATA[    

                    /// <summary>
                    /// Gets text representing the node that can be used for display, such as in a document outline.
                    /// </summary>
                    /// <value>Text representing the node that can be used for display, such as in a document outline.</value>
                    public override string DisplayText {
                        get {
                            return Type.Text + " " + Name.Text;
                        }
                    }

                ]]></AstNodeDeclarations>
            </AstNode>

            <AstNode Name="VariableObjectDeclarationStatement" Inherits="VariableDeclarationStatement" Description="A Variable object declaration statement.">
                <AstNodeProperty PropertyType="Simple" Name="IsConstant" Type="bool" Description="Is the object constant?" />
                <AstNodeProperty PropertyType="AstNode" Name="Expression" Type="Expression" Description="The expression assigned to the object." />
                <AstNodeDeclarations Type="Constructor"><![CDATA[    

                    /// <summary>
                    /// Initializes a new instance of the <c>VariableObjectDeclarationStatement</c> class. 
                    /// </summary>
                    /// <param name="objectType">The object type.</param>
                    /// <param name="objectName">The text of the qualified identifier.</param>
                    /// <param name="isGlobal">Is the object global?</param>
                    /// <param name="isConstant">Is the object constant?</param>
                    /// <param name="expression">The expression assigned to the object.</param>
                    /// <param name="textRange">The <see cref="TextRange"/> of the AST node.</param>
                    public VariableObjectDeclarationStatement(ObjectType objectType, Identifier objectName, bool isGlobal, bool isConstant, Expression expression, TextRange textRange) : this(objectType, objectName, isGlobal, textRange) {
                        // Initialize parameters
                        this.IsConstant = isConstant;
                        this.Expression = expression;
                    }

                ]]></AstNodeDeclarations>
            </AstNode>
Where VariableDeclarationStatement inherits from Statement and VariableObjectDeclarationStatement in turn inherit from VariableDeclarationStatement.

When I put the generated code into my application and compile, I got the following compilation error...

Error    1    'Aisolutions.FreeFlyer.Classic_Project.Input.Ast.VariableDeclarationStatement' does not contain a definition for 'VariableDeclarationStatementContextIDBase'    D:\FreeFlyerNG\sourcecodecsharp\FreeFlyerGUI\Classic Project\Input\Syntax Editor\FFSemanticParser.cs    2547    123    FreeFlyerGUI
The reason for such problem is that VariableDeclarationStatement class does not declare VariableDeclarationStatementContextIDBase for its subclass as Statement class would:

protected const byte StatementContextIDBase = Aisolutions.FreeFlyer.Classic_Project.Input.Ast.AstNode.AstNodeContextIDBase;
Since I try to change the generated code as little as possible, I would like to find out how to take care of this case in parser generator itself.

Please help......

Thanks!
David

Comments (2)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi David,

Right now it's only generating the ID base constants for non-abstract AST nodes. I've changed the code so it will work for all nodes in the next maintenance release.


Actipro Software Support

Posted 12 years ago by David Chang - Software Engineer, a.i. solutions, Inc.
Avatar
Thanks!
The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.