The current Documentation tab follows below. ...

Nov 12, 2012 at 4:46 PM

Hello Pieter

I tried to do something. With below given definition

public class TypedNonTerminal<TAstNode> : TypedNonTerminal<MyAstContext,TAstNode> 
      where TAstNode : AstNode<MyAstContext>{
   }

Error: ...requires 1 Type argument

I don't pretend to understand everything correct, but it seems to me compiler has reason ?

Thank you in advance

Coordinator
Nov 12, 2012 at 7:08 PM
Edited Nov 12, 2012 at 7:14 PM

Hi Dimitrij,

AstGrammarTest.cs includes two examples of use for TypedNonTerminal:

      var expr  = new TypedNonTerminal<ExpressionAstNode>();
      var stmt  = new TypedNonTerminal<StatementAstNode>();
where
public class ExpressionAstNode : AstNode<MyAstContext> {}
public class StatementAstNode  : AstNode<MyAstContext> {}

Does that help?

Pieter

Nov 14, 2012 at 8:25 AM

Hello Pieter
Unfortunately doesn't help.

From the very beginning I had all three classes:
public class ExpressionAstNode      : AstNode<MyAstContext> {}
public class StatementAstNode       : AstNode<MyAstContext> {}
public class StatementListAstNode   : ListNode<MyAstContext> {}
 
But there are various problems.
 
For this definition
 
public class TypedNonTerminal<TAstNode> : TypedNonTerminal<MyAstContext, TAstNode>
      where TAstNode : AstNode<MyAstContext>
{
}
 
Error:   ...  requires 1 type argument
 
I tried to change the definition of TypedNonTerminal<TAstNode> as follows:
 
public class TAstNode : AstNode<MyAstContext>
{
}
public class TypedNonTerminal : TAstNode
{
}
 
var expr = new TypedNonTerminal<StatementListAstNode>();
var stmt = new TypedNonTerminal<StatementListAstNode>();
var stmtList = new TypedNonTerminal<StatementListAstNode>();
 
then apppears the error:
 
The type parameter   ...TypedNonTerminal     cannot be used with type arguments.
 
 
After some changing I’ve got this variant, which is live:
 
public class TAstContext : AstContext
{
   public TAstContext(LanguageData language) : base(language) { }
}
public class TAstNodeType : AstNode<TAstContext> {}
 
public class TypedNonTerminal<TAstContext, TAstNodeType> : NonTerminal
{
   public TypedNonTerminal(string name) : base(name) { }
}
 
var exprNode = new ExpressionAstNode();
var stmtNode = new StatementAstNode();
var stmtListNode = new StatementListAstNode();
 
var expr = new TypedNonTerminal<ExpressionAstNode, MyAstContext>(exprNode.GetType().Name);
var stmt = new TypedNonTerminal<StatementAstNode, MyAstContext>(stmtNode.GetType().Name);
var stmtList = new TypedNonTerminal<StatementListAstNode, MyAstContext>(stmtListNode.GetType().Name);
 
It has been compiled and Grammar Explorer parses the tree.
I’ll be you obliged if you show me incorrect or not necessary or(and) redundant code.

Coordinator
Nov 14, 2012 at 1:10 PM

HI Dmitrij,

You seem to be missing several concepts in regard to Type Parameters and use of Generics. Can I suggest that you read up on these first, before we continue?  Without some common terminology in this regard, we will just waste a lot of time, especially considering the time difference between our locales. Here are some links to start with:

http://msdn.microsoft.com/en-us/library/ms379564(v=vs.80).aspx

http://msdn.microsoft.com/en-us/library/512aeb7t(v=vs.80).aspx

http://msdn.microsoft.com/en-us/library/512aeb7t(v=vs.100).aspx

 

Nov 14, 2012 at 3:13 PM

Hi Pieter

Probably you are right concerning concepts. But first of all I tried simply to repeat the test.

1. And got the first error by definition:

public class TypedNonTerminal<TAstNode> : TypedNonTerminal<MyAstContext,TAstNode> 
      where TAstNode : AstNode<MyAstContext>{
}

OK. My writing was really wrong. Now I think the right definition must look like

public
class TypedNonTerminal<TAstNode> where TAstNode : AstNode<MyAstContext> {}

2. Second point is here:

#region 2-NonTerminals - in camelCase
.....................................
var expr = new NonTerminal<ExpressionAstNode>(); var stmt = new NonTerminal<StatementAstNode>(); var stmtList = new NonTerminal<StatementListAstNode>(); #endregion

NonTerminal<StatementAstNode>() OR TypedNonTerminal<StatementAstNode>() ?

I took TypedNonTerminal<StatementAstNode>()

Now another serie of errors of similar type:

#region 3-Rules
Root = stmtList

impossible to cast to types implicitly

from S
tatementListAstNode to Irony.Parsing.NonTerminal


Probably I need something in these classes ?

public class ExpressionAstNode      : AstNode<MyAstContext> {}
public class StatementAstNode       : AstNode<MyAstContext> {}
public class StatementListAstNode   : ListNode<MyAstContext> {}








Coordinator
Nov 14, 2012 at 3:50 PM

The boilerplate works - STOP PLAYING WITH IT!

Put whatever code you need in:

  • the Grammar constructor;
  • MyAstContext; and
  • the sub-classes of AstNode<MyAstContext>: ExpressionAstNode, StatementAstNode, StatementListAstNode.

Leave the rest alone until you understand how and why it works.

Nov 14, 2012 at 4:22 PM
Edited Nov 14, 2012 at 4:23 PM

Hi Pieter,

I've done everything. But there is a doubt either I don't understand something or there some errors in your code:

public class TypedNonTerminal<TAstNode> : TypedNonTerminal<MyAstContext,TAstNode> 
      where TAstNode : AstNode<MyAstContext>{
}

OR
public
class TypedNonTerminal<TAstNode> where TAstNode : AstNode<MyAstContext> {}
NonTerminal<StatementAstNode>() OR TypedNonTerminal<StatementAstNode>() ?
Coordinator
Nov 14, 2012 at 4:49 PM

"There is no royal road to knowledge." - Aristotle, to Alexander the Great.

Do your homework. Read the links I sent you. When you can explain what the class definition below does, I will answer further questions.

public class TypedNonTerminal<TAstNode> 
: TypedNonTerminal<MyAstContext,TAstNode>       
where TAstNode : AstNode<MyAstContext>{}
Nov 15, 2012 at 9:39 AM

Dear Pieter,

Thank you very much for Aristotle. I repeat my question in another form.

public class new_List<TAstNode> : List<TAstNode> where TAstNode : AstNode<MyAstContext> { }                                    OK

public class new_List<TAstNode> : List<MyAstContext, TAstNode> where TAstNode : AstNode<MyAstContext> { }              error:   requires 1-type argument

public class new_List<TAstNode> : new_List<MyAstContext, TAstNode> where TAstNode : AstNode<MyAstContext> { }       error:   requires 1-type argument

public class new_List<TAstNode> : new_List<TAstNode> where TAstNode : AstNode<MyAstContext> { }                             error:  circlar dependency

First of all I presume that I don't understand something.

Coordinator
Nov 17, 2012 at 1:12 AM

Read this:

http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/a856b728-05df-4439-946a-4966951b6e10