[antlr-interest] [c target] memory leaks during error recovery

Jim Idle jimi at temporal-wave.com
Tue Oct 20 00:59:18 PDT 2009


It is because you are trying to do things while you parse - another reason to build a tree and THEN operate on the tree.

Catch does not need a type in the C target, you can just use:

r:
  Ddddddd
;
catch() { }

(assuming 3.2 of ANTLR).

The other thing you might do is break up your rule list so that exceptions in them do not drop out the whole rule, which is what happens in all targets unless you structure the rules a little. Break things down in to smaller units. The function call overhead (which may not even occur because of inlining) is very small in C.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Ìèõàèë Þðóøêèí
> Sent: Monday, October 19, 2009 2:37 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] [c target] memory leaks during error recovery
> 
> Good day,
> I have the rule
> 
> myRule[returns Type1 res] :
>  rule1, rule2, rule3, rule4... ruleN { res = f($rule1, $rule2,..., ,
> $ruleN) }
>  ;
> 
> it's all ok.
> BUT if ruleN will fire exception, rule1, rule2.. rule(N-1) subtrees
> will
> be forgotten!!!
> How can I manage such situations?? can you write me right code for such
> rule, that gives answer on my question?
> thanks
> 
> PS: I tried to use "catch" attribute .. but it needs errorCode. It's
> not
> good, because there're may be different errors.
> 
> --
> Best regards,
> Michael
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list