home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.compilers
- Path: sparky!uunet!gatech!destroyer!sol.ctr.columbia.edu!eff!world!iecc!compilers-sender
- From: Elliot H. Mednick <elliot@wellspring.com>
- Subject: Interactive stamtment execution
- Reply-To: Elliot H. Mednick <elliot@wellspring.com>
- Organization: Wellspring Solutions
- Date: Wed, 29 Jul 1992 17:32:49 GMT
- Approved: compilers@iecc.cambridge.ma.us
- Message-ID: <92-07-088@comp.compilers>
- Keywords: yacc, interpreter, question
- Sender: compilers-sender@iecc.cambridge.ma.us
- Lines: 57
-
- 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:
-
- S
- : program
- | statement
- ;
-
- program
- : 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
- interactively.
-
- 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
- --
- Elliot H. Mednick P.O. Box 150
- Wellspring Solutions Sutton, MA. 01590
- elliot@Wellspring.com +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]
- --
- Send compilers articles to compilers@iecc.cambridge.ma.us or
- {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.
-