Help required to process nodes as Commands.

Dec 29, 2012 at 11:51 AM


The promise of Irony if amazing. But it's HARD. Help.

I got the Expression sample running. But didn't understand all of it as it's pretty far along from a newbie/entry level.

Trying to go back to basics of a language of simple commands.

Assuming a Grammar (probably wrong ...but its my first time) to define one or more simple Commands:

    public class MyGrammar : Irony.Parsing.Grammar
        public MyGrammar():base(false)

            var program = new NonTerminal("program");

            //Set the Grammar root:
            this.Root = program;

            //How do I define Guids?
            var guid = new StringLiteral("guid");
            var number = new NumberLiteral("number");
            var v = new IdentifierTerminal("v");
            var commandList = new NonTerminal("commandList");

            var ringBellCommand = new NonTerminal("ringBellCommand", typeof(RingBellNode));

            program.Rule = commandList;
            commandList.Rule = MakePlusRule(commandList, null, ringBellCommand);

            ringBellCommand.Rule = ToTerm("ring") + "bell" + (guid | number | v);
            //Q: How do I define the second Command syntax?
            //var honkHornCommand = new NonTerminal("honkHornCommand");
            //honkHornCommand.Rule = ToTerm("honk") + "horn" + (guid | number | v);
            //commandList.Rule = MakePlusRule(commandList, null, honkHornCommand);

            this.LanguageFlags =  LanguageFlags.CreateAst;


The command is backed by an ASTNode (that currently does nothing):


    public class RingBellNode : AstNode 
        public override void Init(Irony.Ast.AstContext context, Irony.Parsing.ParseTreeNode treeNode)
            base.Init(context, treeNode);

        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
            //No idea what to do here yet.
            return base.DoEvaluate(thread);



I then run it with:

        static void Main(string[] args)

            MyGrammar myGrammar = new MyGrammar();

            Parser p = new Parser(myGrammar);

            //Q: what's wrong with grammer that I can't define more than one command?
            ParseTree t = p.Parse("ring bell 3");

            //Q: Now what? How do I execute the command defined in RingBellNode.Evaluate?
            //Or is that not how it's done?

It parses. I've got child nodes in root. (although it won't let me parse more than one command at a time...but that can wait).

The question is...what's the point of a AST on its own? Isn't the AST just an artefact needed for it to in the end invoke the ASTNode? 

If so...HOW!?

Thank you for your help.