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


Groups > comp.compilers > #1073

Re: flex + yacc problem: partial parsing.

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.compilers
Subject Re: flex + yacc problem: partial parsing.
Date 2014-01-08 03:18 +0000
Organization Aioe.org NNTP Server
Message-ID <14-01-006@comp.compilers> (permalink)
References <13-12-008@comp.compilers>

Show all headers | View raw


On 2013-12-17, Kaz Kylheku <kaz@kylheku.com> wrote:
> [You can use YYACCEPT to tell yacc or bison that you're done parsing,
> but I'm not sure about the readahead. -John]

Okay, I got it all working:

http://www.kylheku.com/cgit/txr/commit/?id=c5accb635a0892c685947aa0bb45193f4cd5cb38

In a nutshell:

- had to refactor the grammar so that that an expr can be reduced to the
  start symbol without any lookahead token, as a $default reduction:
  all entries in the parsing table say "reduce", regardless of
  the lookahead token. *-note

- had to add the YYACCEPT; trick to the top reduction.

- to completely solve the lookahead problem down to the lexical level
  (so after extracting an expr, the stream is left in the proper state so that
  another expr can be extracted), I had to change the YYINPUT macro
  to only return one byte at a time. If YYINPUT reads more than one
  byte from the stream, then these accumulated bytes will be thrown
  away when the lexical machine is reinitialized for another yyparse
  job.

----

* This is usually trivial in Lisp grammars, except that I support an
  a .. b operator which is a syntactic sugar for (cons a b), which means
  that if we parse the "a", we need lookahead to determine whether the
  next thing is "..", or EOF.  I refactored it by making the .. operator
  part of the syntax of a compound list expression; it cannot occur
  by itself any more, which is perfectly acceptable.  In other words,
  a .. b is now just syntax, on par with something like the consing
  dot notation, and not an independent expression.  You'd never want
  a top-level expression that is just the equivalent of (cons a b).

--
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List:  http://www.kylheku.com/mp1

Back to comp.compilers | Previous | Next — Previous in thread | 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