Sun, 2 Aug 1992 23:40:14 GMT

          From comp.compilers

Related articles
| List of all articles for this month |

Newsgroups: comp.compilers
From: (A. Walker)
Organization: Monash University, Melb., Australia.
Date: Sun, 2 Aug 1992 23:40:14 GMT
Keywords: yacc, question

Currently I have implemented an awk to C compiler. It needs to
parse the awk source file twice: once to collect and type undeclared
symbols and then to compile the awk source to C. So far this is
implemented by calling yyparse() and then calling yyrestart() in lex,
rewind(yyin) and calling yyparse() again. This works fine using BYACC and
FLEX. However when using BISON (for portability on other platforms)
yyparse() cannot be called a second time, it results in 'parse error'. How
and a BISON (v1.11, v1.18) parse be 'restarted'?

As an alternative i tried creating a lex yywrap() to intercept the first
EOF, and restart. But this results in an incomplete first parse,
presumably because yyparse() is lagging a few tokens behind and _needs_ to
see EOF to complete parsing.

What is the standard approach to parsing a source file multiple times?

If all works out well I'll make this shareware.

Junaid Walker
[Bison is supposed to let you restart a parse by calling yyparse() again.
You may either have a bison bug or an assumption of some sort in your code.
But since yyrestart() is specific to flex, why not just tell people to use
flex and byacc and leave it at that. You can distribute their C output for
people who don't have them on the target machine. -John]

Post a followup to this message

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