[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FW: Confusion



Jim Moores wrote:

> I think I have partly realized my mistake.  I think I should be simply doing
> 
>   PBlock block = node.getBlock();
>   block.apply(this);


Yes, this is fine.  But, usually, it is more convenient to do things in the 
sub-nodes and/or leafs than in the root node, as you do not need to use a 
"switch" to find out the types of sub-nodes.

> and relying on caseABlock to deal with the block.  The problem is that I
> want to emit
> code either side of each statement within the block.  Should I
> 
>   1) detect from within caseABlock that the parent is my ParStatement (or
> something similar)


This is probably a quick and not so dirty solution, if you don't have to deal 
with the first/last statements in a special way.

> or
> 
>   2) create a whole new production for a block that is effectively a copy of
> the original with a different name and implement this special behaviour in
> caseANewBlock?


Using hidden alternatives and the "replaceBy" method (unless you can already 
detect this at the parsing stage), this is an excellent approach, as you now 
separate the "analysis" of the semantics in a separate stage, independent of
code generation.


Etienne


-- 
Etienne M. Gagnon                    http://www.info.uqam.ca/~egagnon/
SableVM:                                       http://www.sablevm.org/
SableCC:                                       http://www.sablecc.org/