home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.compilers
- Path: sparky!uunet!think.com!spdcc!iecc!compilers-sender
- From: quanstro@stolaf.edu (goon)
- Subject: Re: Interactive stamtment execution
- Reply-To: quanstro@stolaf.edu (goon)
- Organization: St. Olaf College, Northfield, MN USA
- Date: Thu, 30 Jul 1992 13:40:20 GMT
- Approved: compilers@iecc.cambridge.ma.us
- Message-ID: <92-07-113@comp.compilers>
- Keywords: interpreter, yacc
- References: <92-07-088@comp.compilers>
- Sender: compilers-sender@iecc.cambridge.ma.us
- Lines: 41
-
- 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.
- --
- Send compilers articles to compilers@iecc.cambridge.ma.us or
- {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.
-