This project has moved and is read-only. For the latest updates, please go here.

Creating non-AstNode syntax trees

Dec 26, 2008 at 10:24 AM
What is the easiest way to create a syntax tree that consists of custom classes that do not derive from AstNode?
Right now I re-read AstNode hierarchy, but this means that I essentially create two hierarchies, which is slower.
Also re-reading iis sometimes quites complex, expecially for optional nodes.

I have found the NodeCreatorMethod, but it can create AstNodes only.
Dec 26, 2008 at 4:50 PM
Assign NodeType property of NonTerminal; it can be any class having a special constructor with AstNodeArgs as argument.
Dec 26, 2008 at 7:05 PM
But Irony.Compiler.Lalr.Parser.CreateNode() does 
return (AstNode) Activator.CreateInstance(ntNodeType, nodeArgs);
which seems to imply that parsing will fail if result can not be cast to AstNode?
Dec 26, 2008 at 7:50 PM
yep, that's a bug. As you see, I had your case in mind but didn't actually try it. It is in my plan to refactor this aspect, to leave only some optional interface for AST node for initialization. When this refactoring will happen - not sure, as soon as I'm finished with NLALR. For now, feel free to change the code so it can run your case. Sorry for trouble
Dec 26, 2008 at 9:17 PM
Ok, thanks, I think I will fix it myself if the performance improvement will seem to be worth it.