Interactive stamtment execution

Elliot H. Mednick <>
Wed, 29 Jul 1992 17:32:49 GMT

          From comp.compilers

Related articles
Interactive stamtment execution (Elliot H. Mednick) (1992-07-29)
Re: Interactive stamtment execution (1992-07-30)
Re: Interactive statement execution (1992-08-04)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Elliot H. Mednick <>
Organization: Wellspring Solutions
Date: Wed, 29 Jul 1992 17:32:49 GMT
Keywords: yacc, interpreter, question

I am writing an interpreter that uses YACC to parse the language. I want
the interpreter to also be able to execute statements interactively. I
would like to use the same YACC description file to parse both the program
and the interactive statements, which are identical to the procederal
statements. However, there are some difficulties.

The language that is to be parsed includes header and declarative
information that YACC needs to know about, as well as the procedural
statements. In "interactive mode", entering declarations would be
illegal; only the statements would be allowed. At the top level, a common
YACC description might look something like this:

  : program
  | statement

  : header declaration statment_list

However, I want YACC to distinguish between parsing a program file and
parsing interactively: i.e. flag syntax errors if a program does not have
declaration and header info and if declaration info is typed

The obvious alternative is to use two YACC descriptions. The big problem
with two descriptions is that the vast majority of the description would
be common between the two files, since the same statements are used and
they would have the same actions. I am considering using BISON since the
sources are avalable, and modifying it to support file inclusion; except
that the interpreter would be sold commercially.

Are there techniques for using the SAME YACC file for parsing different
aspects of a langauge, while excluding undesired aspects? If not, is
there a way to use a common description for two YACC files? And if not
for that, any suggestions on a small source control mechanism for ensuring
both files are up to date w.r.t each other?

Thanks in advance.
Elliot H. Mednick P.O. Box 150
Wellspring Solutions Sutton, MA. 01590 +1 508 865 7271
[The easiest technique is to use a fake initial token to distinguish the
two cases, e.g.:

toplevel: FAKE1 single-statement | FAKE2 statement-list ;

and have the lexer return the appropriate initial fake statement. A harder
problem is to have the lexer return an end marker at the end of a single
statement when the syntax doesn't make that obvious. -John]

Post a followup to this message

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