Posted 18 years ago
by David Chang
-
Software Engineer,
a.i. solutions, Inc.
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: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...The reason for such problem is that VariableDeclarationStatement class does not declare VariableDeclarationStatementContextIDBase for its subclass as Statement class would:
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
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>
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
protected const byte StatementContextIDBase = Aisolutions.FreeFlyer.Classic_Project.Input.Ast.AstNode.AstNodeContextIDBase;
Please help......
Thanks!
David