if expression then logic

23 views
Skip to first unread message

french...@gmail.com

unread,
May 21, 2013, 3:14:30 PM5/21/13
to antlr-di...@googlegroups.com
I am using ANTLR4 and I have created a SQL like grammar, but now I am running into performance issues.

To put my problem into context I have 100,000 people with around 200 Facts each. In one of my queries I only want Facts that occurred between x and y dates for each person, which I then perform some arithmetic on.

My initial implementation of the listener calculated the expression, followed by the arithmetic for each fact. If the expression turned out true then I propagated the arithmetic.

My current attempt is using a a flag so generated from the the expression, so that when walking the arithmetic part of the tree nothing is calculated.

This has produced some improvement but I'm wondering if I am missing something and I should be able to do this at the grammar level, and prevent the walking of the arithmetic section if the expression is false.

Any help would be greatly appreciated... Hopefully I have not gone down the wrong road !

Simon

Sam Harwell

unread,
May 21, 2013, 3:26:14 PM5/21/13
to antlr-di...@googlegroups.com
One thing you can try is instead of using ParseTreeListener.DEFAULT, you can create your own class derived from ParseTreeListener that controls which nodes get walked and which ones do not.

--
Sam Harwell
Owner, Lead Developer
http://tunnelvisionlabs.com
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Terence Parr

unread,
May 21, 2013, 3:28:04 PM5/21/13
to antlr-di...@googlegroups.com
 are you using two-stage parsing that starts with SLL mode? (see the book)
T


--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Dictation in use. Please excuse homophones, malapropisms, and nonsense. 

french...@gmail.com

unread,
May 21, 2013, 3:47:57 PM5/21/13
to antlr-di...@googlegroups.com
It wasn't but it is now!
It didn't really make any difference though.
My speed issue is not in the parsing but the walking of the tree where I'm processing way too much when I shouldn't

Terence Parr

unread,
May 21, 2013, 3:48:48 PM5/21/13
to antlr-di...@googlegroups.com
oh! how about walking tree once and creating an index of nodetype -> list of nodes. Then you can do an efficient search for the nodes you are interested in.
T

french...@gmail.com

unread,
May 21, 2013, 3:53:21 PM5/21/13
to antlr-di...@googlegroups.com
On Tuesday, May 21, 2013 3:26:14 PM UTC-4, Sam Harwell wrote:
> One thing you can try is instead of using ParseTreeListener.DEFAULT, you can create your own class derived from ParseTreeListener that controls which nodes get walked and which ones do not.
>
Hi Sam,
I'm already doing this, and I'm wondering if I'm doing the right thing!
When I have a to loop over records for each person, instead of walking the whole tree again I do it in here.
To be honest I thought it was a complete hack, but maybe this is the way to go!
Thankyou.
Simon
Reply all
Reply to author
Forward
0 new messages