flex + yacc problem: partial parsing.

Kaz Kylheku <kaz@kylheku.com>
Tue, 17 Dec 2013 22:52:28 +0000 (UTC)

          From comp.compilers

Related articles
flex + yacc problem: partial parsing. kaz@kylheku.com (Kaz Kylheku) (2013-12-17)
Re: flex + yacc problem: partial parsing. kaz@kylheku.com (Kaz Kylheku) (2014-01-07)
Re: flex + yacc problem: partial parsing. kaz@kylheku.com (Kaz Kylheku) (2014-01-08)
Re: flex + yacc problem: partial parsing. kaz@kylheku.com (Kaz Kylheku) (2014-01-08)
| List of all articles for this month |
From: Kaz Kylheku <kaz@kylheku.com>
Newsgroups: comp.compilers
Date: Tue, 17 Dec 2013 22:52:28 +0000 (UTC)
Organization: Aioe.org NNTP Server
Keywords: yacc, question, comment
Posted-Date: 17 Dec 2013 20:12:06 EST

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]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.