home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / compiler / 1411 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  2.2 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!darwin.sura.net!udel!gvls1!faatcrl!iecc!compilers-sender
  2. From: drw@euclid.mit.edu (Dale R. Worley)
  3. Newsgroups: comp.compilers
  4. Subject: Re: Simple constant folding in bison parser
  5. Keywords: yacc, attribute
  6. Message-ID: <92-08-110@comp.compilers>
  7. Date: 17 Aug 92 19:25:22 GMT
  8. References: <92-08-020@comp.compilers> <92-08-040@comp.compilers>
  9. Sender: compilers-sender@iecc.cambridge.ma.us
  10. Reply-To: drw@euclid.mit.edu (Dale R. Worley)
  11. Organization: MIT Dept. of Tetrapilotomy, Cambridge, MA, USA
  12. Lines: 31
  13. Approved: compilers@iecc.cambridge.ma.us
  14.  
  15. drw@kronecker.mit.edu (Dale R. Worley) writes:
  16.    Really, what you're doing is constructing a synthesized (passed-upwards)
  17.    attribute (constant vs. non-constant), but most LALR parser generators
  18.    don't support that.  When you're parsing C, you want a lot of these
  19.    attributes, and you want the attributes to control some aspects of the
  20.    parsing.  The result is that some productions are cloned 6 or 8 times.
  21.    Ugh.
  22.  
  23.    [This certainly works, but I'd think it'd be a lot easier to handle
  24.    synthesized attributes in the value cells, where they're easy to
  25.    construct and pass up the tree. -John]
  26.  
  27. It would be for constant folding, but in C, some of the attributes affect
  28. the parsing process, and so can't be added on in a layer of processing
  29. that the parser is blind to.  If I remember correctly, an important action
  30. is to classify declarators as to whether the identifier being declared is
  31. (at present) a typedef name or not.  Typedef-redeclaring declarators can
  32. only appear in declarations that contain "type specifiers" (i.e., int,
  33. float, struct, etc.).  If this restriction is not expressed in the grammar
  34. productions, the grammar is still unambiguous (I think), but it is not
  35. LALR(1).
  36.  
  37. What one would really like to write in the parser is a synthesized
  38. attribute (which is just passed upward in most declarator-building
  39. productions), and then constrain the appropriate productions to use only
  40. declarators with the proper values of the attribute.
  41.  
  42. Dale Worley        Dept. of Math., MIT        drw@math.mit.edu
  43. -- 
  44. Send compilers articles to compilers@iecc.cambridge.ma.us or
  45. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  46.