I'm parsing some source code. How can I ignore the bodies of long methods without overflowing my stack?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Tim_Stewart
Posted On:   Monday, February 11, 2002 10:47 AM

Hi, I would like to capture parameter/return type information about a method but I would like to ignore the internal body of the method. To acheive this, we have come up with: protected subroutineDef : SUB h:methodHeadDef b:subBody SUB! ; protected subBody : ( ("Exit" SUB) => "Exit" SUB | ~(SUB) )* ; methodHeadDef is the rule that grabs the parameter/return type info. The problem with this approach is that in the generated code for subBody(), all tokens found in the sub are put into one long chain of tokens (a linked list basically). When the "head" of   More>>

Hi,


I would like to capture parameter/return type information about a method but I would like to ignore the internal body of the method. To acheive this, we have come up with:

			
protected
subroutineDef
: SUB h:methodHeadDef
b:subBody
SUB!
;

protected
subBody
: ( ("Exit" SUB) => "Exit" SUB
| ~(SUB)
)*
;


methodHeadDef is the rule that grabs the parameter/return type info.


The problem with this approach is that in the generated code for subBody(), all tokens found in the sub are put into one long chain of tokens (a linked list basically). When the "head" of the list is destroyed, it recursively destroys the node it's pointing to which destroys the node it's pointing to (etc.) until the list is destroyed. For large subroutines, this destruction process is causing a stack overflow.


I would like all tokens found in the subroutine to 1) ideally, get immediately thrown away, or 2) be created as children of a common parent.


Thanks!


Tim

   <<Less

Re: I'm parsing some source code. How can I ignore the bodies of long methods without overflowing my stack?

Posted By:   Monty_Zukowski  
Posted On:   Tuesday, February 12, 2002 08:12 AM

Put a "!" on to not build the tree for that rule.

protected
subBody!
: ( ("Exit" SUB) => "Exit" SUB
| ~(SUB)
)*
;

Are you generating code in Java or C++?


About 2), even if you made them the children of a common parent they would still be a long list of tokens, except that now there would be one more token, the parent, with its child being the first token in that list.

Re: I'm parsing some source code. How can I ignore the bodies of long methods without overflowing my stack?

Posted By:   Terence_Parr  
Posted On:   Monday, February 11, 2002 05:46 PM

Hi Tim. What does SUB look like? You have buildAST=true? Wow...you must have a very very deeply nested subroutine for this to overflow. I suspect something else is the problem. What is your k value? Why do you need a predicate in the subBody loop?
About | Sitemap | Contact