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

Whishlist: Passive parsing



Hello,

there is another wish: Passive parsing. Currently, SableCC
generates Lexer and Parsers, which are active until parsing
is completed, which is that methods of lexer and parser are
in the state of being called from the start of the call

Start tree = p.parse();

until the call returns. As InputStreams can block, the whole
parsing thread can block. When creating a parser for network
protocols, it is strongly desireable that lexers and parsers
are passive for the time active parsers would block, in
order to minimize the amount of needed threads.

Passive parsers would work this way:

public class PassiveParsingNetworkReader implements
PassiveNetworkReader {
  <init>() {
    ...
    PassiveParser parser = new
PassiveParser(passiveParserNotificationReceiver);
    PassiveLexer lexer = new PassiveLexer(parser);
    ...
  }

  someBytesWereReceivedFromNetwork(byte[] b,int off,int len)
throws IOException {
    lexer.writeSomeBytes(b,off,len);
  }
  ...
}

Some methods of passiveParserNotificationReceiver are called
at certain events, like "parsing completed", or "new
production parsed".

This way, the methods of parser and lexer are only active
when there is really something to do, they are not active
during waiting for data from the network (or from terminal
input, etc.)

This feature, I think, is especially desireably due to
non-blocking IO in JDK1.4. It will make possible to have one
thread per service, and not one thread per client (where 99%
of those threads are just blocking and consuming OS
resources).

Xuân.