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

Non-member submission from [Roger Keays <roger@ninthave.dyndns.org>]

Date: Tue, 3 Jul 2001 02:01:59 +1000 (EST)
From: Roger Keays <roger@ninthave.dyndns.org>
To: <sablecc-list@sable.mcgill.ca>
Subject: Custom Parser


I know that the consensus is to do AST modifications after parsing, but
nevertheless I am trying to do it all in a single parse (using an
AnalysisAdapter for convenience). However, the information in Appendix D
of Etienne's thesis seems to be out of date.

The only way I have managed to get results is to change the Parser's
`node' object from protected to public, and use something like this :

public class CustomParser extends Parser
    public CustomParser(Lexer lexer)

    AstFix fix = new AstFix();
    private class AstFix extends AnalysisAdapter
        public void caseAParsedModel(AParsedModel thisNode)
           node = null; // node (from Parser) must be public !
           // this does not work
           // thisNode = null;

    protected void filter()

Is there any other way to use an Adapter/Switch class in a custom parser?
I'd rather not do all the code in filter (although I guess it is not such
a big deal).