Note that there are some explanatory texts on larger screens.

plurals
  1. POtraversing an ast having complex conditional expression to generate linq expression
    primarykey
    data
    text
    <p>I'm using Irony.net for generating a parse tree out of the source. Essentially I'm using ExpressionEvaluatorGrammer like grammer for binary expressions (arithmetic, relational and logical/conditional). I want to convert the resultant parse tree into Linq expression by traversing it. However, the tree does not seem to have a formation directly convertable to linq conditional expression. Hypothetical example of such an expression:</p> <pre><code>1 == 1 &amp;&amp; 4 - 1 == 3 </code></pre> <p>generates (pseudo xml tree for brevity):</p> <pre><code>&lt;binary&gt; &lt;binary&gt; &lt;binary&gt; &lt;literal&gt;1&lt;/literal&gt; &lt;op&gt;==&lt;/op&gt; &lt;literal&gt;1&lt;/literal&gt; &lt;/binary&gt; &lt;op&gt;&amp;&amp;&lt;/op&gt; &lt;binary&gt; &lt;literal&gt;4&lt;/literal&gt; &lt;op&gt;-&lt;/op&gt; &lt;literal&gt;1&lt;/literal&gt; &lt;/binary&gt; &lt;/binary&gt; &lt;op&gt;==&lt;/op&gt; &lt;literal&gt;3&lt;/literal&gt; &lt;/binary&gt; </code></pre> <p>In the tree above, the arithmetic expression (4 - 1) becomes the right expression to the &amp;&amp; logical operation as the parent node closes after it. In the ideal world, it should have been a left expression of the nodes representing "== 3".</p> <p>How do you traverse such a tree to generate a proper and operation? Or, is there a way to generate the tree in the form I desire?</p> <p>Edit: here's the grammer (partial) definition. I have taken it from ExpressionEvaluatorGrammer that comes with Irony.interpreter.</p> <pre><code>RegisterOperators(15, "&amp;", "&amp;&amp;", "|", "||"); RegisterOperators(20, "==", "&lt;", "&lt;=", "&gt;", "&gt;=", "!="); RegisterOperators(30, "+", "-"); RegisterOperators(40, "*", "/"); Expr.Rule = Term Term.Rule = number | ParExpr | stringLit | FunctionCall | identifier | MemberAccess | IndexedAccess; ParExpr.Rule = "(" + Expr + ")"; BinExpr.Rule = Expr + BinOp + Expr; BinOp.Rule = ToTerm("+") | "-" | "*" | "/" | "**" | "==" | "&lt;" | "&lt;=" | "&gt;" | "&gt;=" | "!=" | "&amp;&amp;" | "||" | "&amp;" | "|"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload