Convert Grammar

Oct 3, 2013 at 9:42 AM
Hi List,
i have to convert functions from Irony 1.0 to the ExpressionevaluatorGrammer
(Irony.Interpreter.2012)

The old Syntax Looks like this:
x = Parameters!Param1

the grammer was defined as
var parameterSectionStmt = new NonTerminal("ParameterSectionStmt");
parameterSectionStmt.Rule = ParameterSection + exclamationMark + identifier;

Expr.Rule = Symbol("null")
            | boolean
            | nil
            | stringLiteral
            | numberLiteral
            | QualifiedName
            | FunctionExpression
            | LCb + Expr + RCb
            | LFb + QualifiedName + RFb
            | Conditional
            | BinExpr
            //| Expr + BinOp + Expr
            //| LUnOp + Expr

            | parameterSectionStmt
            | globalSectionStmt
            | userSectionStmt
            | fieldsSectionStmt;
QualifiedName.Rule = identifier
            | QualifiedName + dot + identifier 
            | parameterSectionStmt + "!" + identifier 
            | "#" + identifier ;
Any ideas
Thanks
Peter
Coordinator
Oct 3, 2013 at 4:38 PM
sorry, any ideas about what? is there a problem? Just replace a few renamed functions/classes like "Symbol(str)" changed to ToTerm(). Everything else should be straightforward
Roman
Oct 4, 2013 at 5:57 PM
Edited Oct 4, 2013 at 6:00 PM
Hi,
call me stupid.
What i have:

var ParametersSection = new NonTerminal("ParametersCall",typeof(ParametersCallNode));

Expr.Rule = Term | UnExpr | BinExpr | PrefixIncDec | PostfixIncDec | TernaryIfExpr | ParametersSection;

ParametersSection.Rule = "Parameters" + "!" + identifier;

I try this grammer with:

var g = new BackupGrammar();
var eval = new ExpressionEvaluator(g);

var script = "Parameters!param1";
var result = eval.Evaluate(script);

and get:
Syntax error, expected: operator, assignment operator, ., [

But further on......
Thanks in advance
Peter
.
Coordinator
Oct 4, 2013 at 6:03 PM
One thing I see: use ToTerm("Parameters") in ParameterSection's Rule; the way you have it operator overloading would not kick in and the first two strings in expr will be concatenated into one
Oct 4, 2013 at 8:38 PM
Hi,
this way

ParametersSection.Rule = ToTerm("Parameters") + "!" + identifier;
the syntax error is gone.

Works perfectly.
Thanks Peter
Oct 11, 2013 at 6:35 PM
Hi,
me again.
Most of my conversions work perfectly.

One more Problem:


var GlobalSection = new NonTerminal("GlobalSection",typeof(GlobalsNode));


GlobalSection.Rule = GlobalSection + exclamationMark + Symbol("PageNumber")
    | GlobalSection + exclamationMark + Symbol("TotalPages")
    | GlobalSection + exclamationMark + Symbol("ExecutionTime")
    | GlobalSection + exclamationMark + Symbol("ReportFolder")
    | GlobalSection + exclamationMark + Symbol("ReportName");
How can i convert this rule, and, how to implement errorhandling if there is a wrong Statement after the 'exclamationmark'.

Thanks in advance
Peter
Coordinator
Oct 15, 2013 at 5:10 PM
sorry for late reply, was just hoping somebody else will jump in, the question seems to be simple to answer.
do the following:
GlobalSection.Rule = GlobalSeciont + exclMark + GlobalSectionSuffix;
GlobalSectionSuffix.Rule = ToTerm("PageNumber") | "TotalPages" | "ExecutionTime" | .... ;
Oct 15, 2013 at 7:27 PM
Hi,
there is nothing to excuse.

I found the solution by myself g

First i try your solution, but change to this:

GlobalSection.Rule = ToTerm("Globals") + exclamationMark + identifier;

so i can have a clear errorhandling in my AstNode:
protected override object DoEvaluate(ScriptThread thread)
    {
        thread.CurrentNode = this;  //standard prolog
        var pi = thread.GetPageInfo();

        var test = globalNode.AsString.ToLower();
        if ( test == "pagenumber") {
            Console.WriteLine("pagenumberr");
            return pi.PageNumber;
        } else if (test == "pages") {
            return pi.TotalPages;
        } else if (test == "reportname") {
            return pi.ReportName;
        } else if (test == "reportfolder") {
            return pi.ReportFolder;
        } else if (test == "reportfilename") {
            return pi.ReportFileName;
        } 

        else {
            return String.Format("Syntaxerror in Globals <{0}>",globalNode.AsString);
        }
    }
The reason is:
I use Irony in SharpDevelop.Reporting, the ReportGenerator of SharpDevelop.

A ReportColumn contains Text like '= 'Page ' + Globals!PageNumber + ' of ' + Global!Pages this Expression evaluates to

Page 1 of 10 or, if syntaxerror to 'Syntaxerror in Globals <xxxx>

So, if the user makes a typo, he have a clear errormessage where to look, because i Show the message in the

Thanks
Peter