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

Re: Feature request



Etienne Gagnon writes:
> I've looked quickly at your suggestion. There are at least two ways of
> achieving your requested functionality without modifying SableCC.
> 
> The idea is to first recognize that you need two different parsers.
> 
> The most common case (99,9% of SableCC users) is already handled by SableCC.
> It consists in simply using two different packages (and grammar files), one
> for each parser/AST. This is easy enough, so I won't elaborate more.
> 
> The other solution is for the unlikely case you where have some need for the
> two parsers to share the same AST.

Hmm.. your examples are good practical solutions to the problem;
however, I was really wondering more in theoretical terms...

The theoretical question being: how hard would it be to make the
following code possible? (I don't actually need to do this right now,
though it seems like a great feature to have (especially if you view
SableCC as a 'competitor' to other compiler-generators))

  InputStreamReader r = new InputStreamReader(System.in);
  Parser p = new Parser(new Lexer(r), PSomeRandomProduction.class);
  try {
    PSomeRandomProduction ast = p.parse();
  } catch (ParserException e) {
    ...

I mean, from a software designer's (ie, your) point of view (I've
read the dreaded Dragon book (but it was a while ago)), how would
the states and transitions have to be augmented for this to work?
How would the standard compiler generation algorithm have to change?

My guess is that this would require only a linear increase in the size
of the automatically generated stuff, plus a few lines of new code.

This would be a more elegant solution than your two proposals --
which are perfectly valid as practical solutions, but really fall
under the "workaround" category.

Just to reiterate: I think SableCC is great and am perfectly happy
with it for my application.. but the design and implementation of
it are very cool and interesting in their own right, and I think
could get even cooler. Even if nobody has the time to implement them,
it's fun to think about what new features could be added, etc.

-Archie

___________________________________________________________________________
Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com