Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end From: Kaz Kylheku Newsgroups: comp.compilers Subject: flex + yacc problem: partial parsing. Date: Tue, 17 Dec 2013 22:52:28 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 54 Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <13-12-008@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: leila.iecc.com 1387329126 79338 64.57.183.58 (18 Dec 2013 01:12:06 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Wed, 18 Dec 2013 01:12:06 +0000 (UTC) Keywords: yacc, question, comment Posted-Date: 17 Dec 2013 20:12:06 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1063 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]