[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Non-member submission from [Othman Alaoui <oalaou@po-box.mcgill.ca>]
Date: Sun, 07 Nov 1999 12:20:57 -0500
From: Othman Alaoui <oalaou@po-box.mcgill.ca>
Subject: Re: Zebu and SableCC (was Re: Simple SableCC Example)
To: sablecc-list@sable.mcgill.ca
Andrew Cooke wrote:
>As I said, I've no idea how this translates into Java for SableCC, I
>just thought it was elegant. Maybe it will give you some useful ideas.
The following code does something similar in Java for SableCC, for an
argument list of a function, except that it replaces the function
subtree
itself. That's if I understood correctly the purpose of your code...
correct
me otherwise.
The context of the code is a DepthFirstAdapter subclass, as one might
guess...
protected LinkedList argumentList;
public void inAFunction(AFunction node) {
argumentList = new LinkedList();
}
public void inAArgument(AArgument node) {
argumentList.add(node);
}
public void outAFunction(AFunction node) {
ASimplerFunction newNode = new ASimplerFunction(
node.getType(),
node.getIdentifier(),
argumentList,
node.getCompoundstm());
node.replaceBy(newNode);
}
for the following grammar production:
function =
P.type identifier l_par arguments? r_par compoundstm | //
replaced
// for AST transformation
({simpler} P.type identifier argument* compoundstm);
arguments =
{one} argument |
{many} arguments comma argument;
enjoy!