Hi Emanuele,

Your solution seems excellent! The solution I suggested was relatively similar, but without the need for a list. It would have looked something like:

public void caseATermAndTerm(...) {  // caseXXX instead of outXXX
  BinaryQuery q = new BinaryQuery();
  q.setOperator("AND");
  q.setQ1(computeQuerty(node.getTerm()));
  q.setQ2(computeQuerty(node.getFactor()));
  this.computedQuery = q;
}

Note that I didn't need to reverse the order of Q1 and Q2.

Have fun!

Etienne

On 2011-05-15 19:21, Emanuele Ianni wrote:
Hi Etienne. I actually solved my problem this morning at 4AM :)
I recently had my AI final exam so I was fresh of Prolog.
So I though about recursion and about using an accumulator like when you reverse a list in Prolog. First I tried with the currentQuery but it wasn't working, instead I've used a LinkedList so when I end up in a query node I do something like:

    public void outATermAndTerm( ATermAndTerm node) {
        BinaryQuery q = new BinaryQuery();
        q.setOperator("AND");
        q.setQ2(queryBuffer.pollLast());
        q.setQ1(queryBuffer.pollLast());
        queryBuffer.add(q);
    }

Thanks for the code, I'll read that.

--
Etienne M. Gagnon, Ph.D.
SableCC:http://sablecc.org


_______________________________________________
SableCC-Discussion mailing list
[email protected]
http://lists.sablecc.org/listinfo/sablecc-discussion

Reply via email to