Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #76546

Re: Data IO for project

From Nobody <nobody@nowhere.invalid>
Newsgroups comp.lang.c
Subject Re: Data IO for project
Date 2015-11-19 19:59 +0000
Organization A noiseless patient Spider
Message-ID <pan.2015.11.19.19.59.07.387000@nowhere.invalid> (permalink)
References <n2kob0$68v$1@speranza.aioe.org>

Show all headers | View raw


On Thu, 19 Nov 2015 16:03:10 +0100, Morten W. Petersen wrote:

> So I'm working on my XML parser, and a while back someone mentioned that
> having a feed(parser, data) function would be a good idea.
> 
> But how do I make that work in practice?  The XML parser loop would have
> to wait for new input, and what's a good way to design that?  Same goes
> for output and waiting for write access.

What is this "parser loop" of which you speak?

The feed(parser, data) idiom only makes sense in the context of a "push"
parser, where you push data into it and the parser invokes callbacks as
complete terms (attributes, tags, elements, etc) are parsed.

For a "pull" parser, the data flow is reversed: you provide a stream and
the parser pulls data from it as it sees fit.

A push parser is typically implemented as a pushdown automaton.

A pull parser may be implemented as a recursive-descent parser, or as as a
pushdown automaton plus a loop which reads chunks of input which is fed
into the automaton a character at a time until reaching a state
corresponding to a complete element, at which point it returns the element
to the caller. Or it may just build the entire tree in memory and return
the root node to the caller.

Push parsers tend to be more useful in the case where the program can't
just block until all of the data has been received. In that situation, a
recursive-descent parser would need to use some kind of threading: either
actual OS threads or an equivalent such as coroutines or lightweight
threads (e.g. Windows "fibers" or POSIX' swapcontext()).

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Data IO for project "Morten W. Petersen" <morphex@gmail.com> - 2015-11-19 16:03 +0100
  Re: Data IO for project Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-19 08:12 -0800
    Re: Data IO for project "Morten W. Petersen" <morphex@gmail.com> - 2015-11-19 18:42 +0100
      Re: Data IO for project Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-19 12:15 -0800
      Re: Data IO for project Robert Wessel <robertwessel2@yahoo.com> - 2015-11-19 16:17 -0600
        Re: Data IO for project "Morten W. Petersen" <morphex@gmail.com> - 2015-11-20 01:16 +0100
          Re: Data IO for project Robert Wessel <robertwessel2@yahoo.com> - 2015-11-20 00:15 -0600
            Re: Data IO for project "Morten W. Petersen" <morphex@gmail.com> - 2015-11-21 00:37 +0100
  Re: Data IO for project Nobody <nobody@nowhere.invalid> - 2015-11-19 19:59 +0000
    Re: Data IO for project "Morten W. Petersen" <morphex@gmail.com> - 2015-11-20 01:26 +0100
      Re: Data IO for project Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-19 16:46 -0800
      Re: Data IO for project Nobody <nobody@nowhere.invalid> - 2015-11-20 05:08 +0000
        Re: Data IO for project Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-20 02:21 -0800
  Re: Data IO for project Ian Collins <ian-news@hotmail.com> - 2015-11-20 12:00 +1300
    Re: Data IO for project "Morten W. Petersen" <morphex@gmail.com> - 2015-11-20 01:19 +0100
    Re: Data IO for project asetofsymbols@gmail.com - 2015-11-21 12:29 -0800
      Re: Data IO for project Ian Collins <ian-news@hotmail.com> - 2015-11-22 12:13 +1300

csiph-web