Related articles |
---|
Interactive stamtment execution elliot@wellspring.com (Elliot H. Mednick) (1992-07-29) |
Re: Interactive stamtment execution quanstro@stolaf.edu (1992-07-30) |
Newsgroups: | comp.compilers |
From: | quanstro@stolaf.edu (goon) |
Organization: | St. Olaf College, Northfield, MN USA |
Date: | Thu, 30 Jul 1992 13:40:20 GMT |
Keywords: | interpreter, yacc |
References: | 92-07-088 |
elliot@wellspring.com (Elliot H. Mednick) writes:
[how can I use one parser for both interactive and batch parsing?]
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:
S
: program
| statement
;
program
: header declaration statment_list
;
Just modify the productions.
header
: ... { if (interactive) YYERROR; ...}
declaration
: ... { if (interactive) YYERROR; ...}
Or if you want to get really fancy, then make the lexer
interactiveness-aware.
PS: Whenever designing a language that is supposed to be interactive _and_
batch, I think long and hard about doing anything dependent on the output
of isatty(). It's awful confusing for the user, especially when something
typed in interactively gives errors when cut-and-pasted into a file, or
conversely If you can manage to get along without the headers and
declarations in interactive mode, why bother? If you allow headers and
declarations in batch mode, why bother making them illegal in interactive
mode.
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.