[antlr-interest] Re: Suggestion for Parser

marcschellens m_schellens at hotmail.com
Wed Apr 23 23:56:49 PDT 2003


--- In antlr-interest at yahoogroups.com, Ric Klaren <klaren at c...> wrote:
> Hi,
> 
> On Mon, Apr 21, 2003 at 10:45:48AM -0000, marcschellens wrote:
> > It would be convenient, to have a tree parser,
> > which doesn't actually check the tree anymore, as this is done
> > before with another tree parser.
> 
> On Tue, Apr 22, 2003 at 05:41:13AM -0000, marcschellens wrote:
> > I mean a tree walker, with no calls to the match(...)
> 
> No match would imply that syntactic predicates would not work anymore.
> Often match calls look redundant in generated code since just before
it the
> node is checked in a case. In some situations this will not be the case
> thus blowing things up. Also the match code contains the checks for the
> null pointer sentries, which is another can of worms altogether.
> 
> > function and no case statements (c++ mode) or at least
> > (maybe even better) that case statements could be suppressed
> > for some functions as the next sibling is determined by its
> > predecessor.
> 
> It kindoff sounds like you want an unfolding for every possible tree
> traversal ? Which would not be practical for the general case. For some
> subclass of grammars it might be ok.
> 
> > > See the tinybasic.g example for ideas on how to do an interpreter.
> > I had a short look at it, but I think it suffers (in terms of
> > performance) from the same problem, that in some places it checks
> > for the next sibling, even all this information could be delivered
> > from a first tree walk.
> >
> > EG: A switch statement.
> > The first node would contain the number N of case entries
> > so the type (=function to call) is already known for the next
> > N siblings.
> 
> > Are there any plans in this direction?
> 
> No.
> 
> > Where are the crucial lines in the java code?
> 
> CppCodegenerator.java and all the lines involving generating 'match'
calls.
> 
> If you know what you are doing and understand the grammar you have very
> well (and it doesn't use syntactic predicates) you may get away by
using a
> hacked codegenerator. YMMV. 

Of course I don't use syntactic predicates in the interpreter.
A quick solution would be to overload the match function
for my interpreter class. Maybe that is the easiest and savest.
An empty function body probably gets optimized out anyway.
After having a quick look at the code generator, I realized,
that I am much better of, if I hack the interpreter instead :-)
Thanks for your replies,
marc







 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list