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

Need Help

Sep 17, 2012 at 5:55 PM

Hi All,

I'm new to irony and I need assistant with the following.  I need to create a format function to accept one variable and five numeric values.

eg. format(variable,1,1,1,1,1) and can inserted to other functions as well like =if(x="a","ok",format("b",1,1,1,1,1))

this is what  I got so far

public const string FormatStr = "Format"

var variable = new IdentifierTerminal("Variable");

var expr = new NonTerminal("Expression");

var formatExpr = new NonTerminal("Format", typeof(ExpressionListNode));

formatExpr.Rule = ToTerm(FormatStr) + ToTerm("(") + variable + ToTerm(",") +                                    expr + ToTerm(",") + expr + ToTerm(",") + expr +                                    ToTerm(",") + expr + ToTerm(",") + expr + ToTerm(")");    


each numeric value will triggered an events, how would I handle that?  do I call my code to parse the conditions when the validation is done?



Sep 19, 2012 at 5:05 AM

don't quite understand the question - you need to custom-handle the event when the "format" call is parsed? I suggest simply to hook to formatExpr.Reduced event - it is fired when non-terminal (formatExpr) is recongized and "formed" - you can get all numeric arguments as child parse nodes in the event args and fire more events or do specific processing there.

One note - you don't have to use ToTerm call so much - you need it only if the first 2 terms in the rules are string literals; otherwise, you can skip them:

formatExpr.Rule = ToTerm(FormatStr) + "(" + variable + "," + expr + "," + expr + "," + expr + "," + expr + ")"; 

Sep 21, 2012 at 4:35 AM

Thanks rivantsov for replying to my question.  I got most of what I need, but I ran into another problem.  Continue from my first post.  How would I handle If the last three expr (expressions) if 1 represent boolean true and 0 represent boolean false? 


Sep 21, 2012 at 5:46 PM

now I'm confused. what do you mean "handle"? what are we talking about parsing the expression, or interpreting/executing it? if you execute it and want to interpret "1" as true then you need to add the appropriate code in AST node's Evaluate method.

Sep 21, 2012 at 10:23 PM

Hi rivantsov,

Sorry for the confusion.  What you said is what  I need, but I am still struggling with AST node.  Could you provide a sample on how I could do this?  Does it make sense to put it logic expression in the Grammar? If so, how?

Thanks again.

Sep 23, 2012 at 5:13 AM

Look at expression Evaluator, in Grammar.Interpreter assembly. Class ExpressionEvaluatorRuntime adds a global built-in method "format" implemented by a custom method BuiltInFormatMethod. That's exactly what you're looking for. You need to alter this method if you need some "custom" treatment of certain parameters.