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


Groups > comp.compilers > #1063

flex + yacc problem: partial parsing.

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.compilers
Subject flex + yacc problem: partial parsing.
Date 2013-12-17 22:52 +0000
Organization Aioe.org NNTP Server
Message-ID <13-12-008@comp.compilers> (permalink)

Show all headers | View raw


Does anyone have a nice hack (portable across Yacc implementations)
whereby multiple calls to yyparse() can be used to cleanly extract the major
constituents from a stream?

I'm running into the problem that yacc throws a syntax error when
there is extra material after the syntactic unit which it has parsed.

I not only want to suppress that error, but also not to have yacc read
ahead into the stream at all: not to ask for the next token. For instance if
the stream contains two expression slike (a b c) (x y z), I want the parser to
just extract (a b c) and leave the subsquent ( token alone (leaving
that for the next call to yyparse).

Essentially, what I want is LR(0) type behavior in cases where the only
possible action is a reduction, regardless of lookahead. I mean, the closing
parenthesis necessarily closes the expression *regardless of what follows*.
What follows could be the end of the stream, or any token.

Yacc's tables have this info. For some states, there is sometimes only the
default reduce action, and no shift actions: the whole table row is filled with
reduces.

But there is also the problem of the parser insisting on matching the pseudo
token $end. From Bison's y.output:

        state 30

            0 $accept: spec . $end

            $end  shift, and go to state 154


        state 154

            0 $accept: spec $end .

            $default  accept

In this particular case, I want something else. More like:

        state 30

            0 $accept: spec .

            $default accept

So in a nutshell, I want the parser not to read ahead any tokens in situations
where there is only a default reduce action with no shift, and not to constrain
the start symbol to be followed by $end.

--
ADA MP-1 Mailing List: http://www.kylheku.com/mp1
[You can use YYACCEPT to tell yacc or bison that you're done parsing,
but I'm not sure about the readahead. -John]

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


Thread

flex + yacc problem: partial parsing. Kaz Kylheku <kaz@kylheku.com> - 2013-12-17 22:52 +0000
  Re: flex + yacc problem: partial parsing. Kaz Kylheku <kaz@kylheku.com> - 2014-01-07 23:56 +0000
  Re: flex + yacc problem: partial parsing. Kaz Kylheku <kaz@kylheku.com> - 2014-01-08 03:18 +0000
    Re: flex + yacc problem: partial parsing. Kaz Kylheku <kaz@kylheku.com> - 2014-01-08 18:29 +0000

csiph-web