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


Groups > comp.lang.c > #76578

Re: Data IO for project

From "Morten W. Petersen" <morphex@gmail.com>
Newsgroups comp.lang.c
Subject Re: Data IO for project
Date 2015-11-20 01:26 +0100
Organization Aioe.org NNTP Server
Message-ID <n2lpas$tl8$1@speranza.aioe.org> (permalink)
References <n2kob0$68v$1@speranza.aioe.org> <pan.2015.11.19.19.59.07.387000@nowhere.invalid>

Show all headers | View raw


On 19.11.2015 20:59, Nobody wrote:
> 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()).

Well there has been talk on whether it should be possible to make use
of an incomplete document in this thread by Malcolm, and I think that's
a nice feature to have.  If it isn't too difficult to implement or
expensive at run-time.

The design today is a loop that "pulls" characters from a buffer, and
that's an OK design..  so something that enables retrieving characters
from a source is what fits with the code as it is now.

-Morten

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