Question about identifier referencing

Aug 28, 2014 at 10:58 PM
Edited Aug 29, 2014 at 12:45 AM
I have constructed a language that basically looks like:
<Program> ::= <AssignmentStmt> + <BooleanCheck>

The program language is English like:
"set j = 5;"
"Check that j == 5;"

I have created a BooleanCheckNode that simply evaluates the BinaryExpression which is the third node (j == 5 in this case). The Assignment statement seems to work fine on it's own, but the BooleanCheck only works with numbers (like 5 == 5) and seems to think that the identifier 'j' is null and I get a Null Reference Exception. Why would this be?

Here is a snippet from ProgramNode.cs:
public class ProgramNode : AstNode
    {

        public override void Init(AstContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);
            TreeNode = treeNode;
        }
        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            thread.CurrentNode = this;  //standard prolog
            var assgn = (AssignmentNode)TreeNode.ChildNodes[0].AstNode;
            var result = assgn.Expression.Evaluate(thread);
            var bc = (BooleanCheck)TreeNode.ChildNodes[1].AstNode;
            // binexpr is a BooleanCheck var that simply grabs the third child node

            var result2 = bc.binexpr.Evaluate(thread);
            thread.CurrentNode = Parent; //standard epilog
            return result2;
            //return VBRCheckStmt.Evaluate(thread);
        }
Thanks in advance!

----- Edit ------
So it seems that my ScriptApp is without any globals... seems to be a clue. Still trying to debug.
Aug 29, 2014 at 1:25 AM
So I think I know what I was doing wrong, and hopefully someone can confirm my hunch.

I went and took a look at StatementListNode and in Init it iterates the children and calls AddChild() to add to the list. Then later when we Evaluate, we are operating on member ChildNodes which are a part of the ScriptApp due to the Init.

My trouble was using use the TreeNode copy, which didn't (but could've) add children to the ProgramNode.

When I lifted the StatementListNode code, everything worked perfectly - I only had to add a DoEvaluate override to my custom BooleanCheck and it now all works well.

So is my hunch correct? AddChild is a pretty darn important call for registering Globals?

Thanks!
Coordinator
Sep 7, 2014 at 6:42 AM
hi
Don't quite understand what you're doing and your question/smth you want to be confirmed, seems like you try to 'evaluate' expression using some explicit conversions of child nodes, and apparently wasn't doing it correctly. Look at expr evaluator, and get to know how it works. AstNodes form a tree which is 'evaluated' by a 'visitor', while actual data values and results are stored in stack of Frames/Scopes with Globals being top stack frame.