home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / compiler / 1292 < prev    next >
Encoding:
Text File  |  1992-07-30  |  1.9 KB  |  56 lines

  1. Newsgroups: comp.compilers
  2. Path: sparky!uunet!think.com!spdcc!iecc!compilers-sender
  3. From: quanstro@stolaf.edu (goon)
  4. Subject: Re: Interactive stamtment execution
  5. Reply-To: quanstro@stolaf.edu (goon)
  6. Organization: St. Olaf College, Northfield, MN USA
  7. Date: Thu, 30 Jul 1992 13:40:20 GMT
  8. Approved: compilers@iecc.cambridge.ma.us
  9. Message-ID: <92-07-113@comp.compilers>
  10. Keywords: interpreter, yacc
  11. References: <92-07-088@comp.compilers>
  12. Sender: compilers-sender@iecc.cambridge.ma.us
  13. Lines: 41
  14.  
  15. elliot@wellspring.com (Elliot H. Mednick) writes:
  16.  [how can I use one parser for both interactive and batch parsing?]
  17.  
  18.  The language that is to be parsed includes header and declarative
  19.  information that YACC needs to know about, as well as the procedural
  20.  statements.  In "interactive mode", entering declarations would be
  21.  illegal; only the statements would be allowed.  At the top level, a common
  22.  YACC description might look something like this:
  23.  
  24.    S
  25.     : program
  26.     | statement
  27.     ;
  28.  
  29.    program
  30.     : header declaration statment_list
  31.     ;
  32.  
  33. Just modify the productions.
  34.  
  35.    header
  36.     : ...            { if (interactive) YYERROR; ...}
  37.  
  38.    declaration
  39.     : ...            { if (interactive) YYERROR; ...}
  40.  
  41.  
  42. Or if you want to get really fancy, then make the lexer
  43. interactiveness-aware.
  44.  
  45. PS: Whenever designing a language that is supposed to be interactive _and_
  46. batch, I think long and hard about doing anything dependent on the output
  47. of isatty(). It's awful confusing for the user, especially when something
  48. typed in interactively gives errors when cut-and-pasted into a file, or
  49. conversely If you can manage to get along without the headers and
  50. declarations in interactive mode, why bother? If you allow headers and
  51. declarations in batch mode, why bother making them illegal in interactive
  52. mode.
  53. -- 
  54. Send compilers articles to compilers@iecc.cambridge.ma.us or
  55. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  56.