Jan 17, 2012 at 6:25 AM
Edited Jan 17, 2012 at 6:27 AM
|
Hello,
I have same problem with operators associativity. I have following grammar:
using Irony.Interpreter;
using Irony.Interpreter.Ast;
using Irony.Parsing;
using IronyTests.AST;
namespace IronyTests.Grammars
{
public class SimpleCalcGrammar : InterpretedLanguageGrammar
{
#region .ctors
public SimpleCalcGrammar()
: base(false)
{
NumberLiteral number = TerminalFactory.CreateCSharpNumber("number");
IdentifierTerminal identifier = TerminalFactory.CreateCSharpIdentifier("identifier");
NonTerminal expression = new NonTerminal("expression");
NonTerminal binexpr = new NonTerminal("binexpr", typeof(BinaryOperationNode));
NonTerminal parexpr = new NonTerminal("parexpr", typeof(BracketsNode));
NonTerminal fncall = new NonTerminal("fncall", typeof(IronyTests.AST.FunctionCallNode));
NonTerminal binop = new NonTerminal("binop");
expression.Rule = parexpr | binexpr | number | fncall;
parexpr.Rule = "(" + expression + ")";
binexpr.Rule = expression + binop + expression;
binop.Rule = this.ToTerm("+") | "-" | "/" | "*" | "%";
fncall.Rule = identifier + "(" + expression + ")";
this.RegisterBracePair("(", ")");
this.RegisterOperators(1, Associativity.Left, "+", "-");
this.RegisterOperators(2, Associativity.Left, "*", "/", "%");
this.MarkTransient(expression, binop);
this.Root = expression;
this.LanguageFlags = Irony.Parsing.LanguageFlags.CreateAst;
}
#endregion
}
}
I test my grammar by using following code:¨
SimpleCalcGrammar g = new SimpleCalcGrammar();
Parser p = new Parser(g);
ParseTree t = p.Parse("2+3*3*3");
Irony.Interpreter.ScriptApp interpreter = new Irony.Interpreter.ScriptApp(new LanguageData(new SimpleCalcGrammar()));
object vvv = interpreter.Evaluate("2+3*3*3");
I dont know why but result of Evaluate method call is 33 but valid result is 29. Can you please help me?
Thank you very much.
|
|
Coordinator
Jan 17, 2012 at 3:06 PM
|
Confirmed, this is a bug, or more like design flaw. Will fix it
thanks and sorry for trouble
|
|
Coordinator
Jan 23, 2012 at 3:01 AM
|
should be fixed now, in the latest version
Roman
|
|