Parsing one statement at a time

Peter Garst <>
Wed, 11 Dec 91 07:24:11 PST

          From comp.compilers

Related articles
Statement at a time parsing with yacc (1991-12-06)
Parsing one statement at a time (Peter Garst) (1991-12-11)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Peter Garst <>
Keywords: parse
Organization: Compilers Central
References: 91-12-036
Date: Wed, 11 Dec 91 07:24:11 PST

Przemek Skoskiewicz asked about parsing a statement at a time:

> I have a nifty parser for a C-like language. I can run it on a file or a
> string containing one statement and everything is cool. What I want it to
> do is to point to a file and ask it to parse *one* statement only, even if
> there are many statements in sequence in the file.

We supply a system called ydb (100% backward compatible with yacc)
which does this two ways:

1. You can do incremental parsing - you can return from any parser action,
      and then continue the parse from where you left off by calling
      yyparse() again. In the example, one of the actions could have been
      written as

statement { return($1);}

      and the main program could have been something like

while ((stmt = yyparse()) != NULL)

2. As of the new release - now in beta test - you can specify multiple
      entry points for your parsers. The grammar could have been written as

%export statement


top_statements: ...

      Then in the main program you could call the routine yyparse() to parse
      everything, or statement() to parse only a single statement.

Besides providing these and other useful extensions to yacc, the system
provides extensive tools for debugging grammars and parsers. For example,
it can generate examples of conflicts, showing how the parse would go on
one or the other branch, and it can automatically generate precedence
systems. At run time it can trace or break on grammar rules, particular
input symbols and other events.

Peter Garst

Bloomsbury Software Group
POBox 390018
Mountain View, CA 94039 USA
(415) 964-3486

Post a followup to this message

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