home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / compiler / 1424 < prev    next >
Encoding:
Text File  |  1992-08-20  |  1.8 KB  |  43 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!cs.utexas.edu!rutgers!faatcrl!iecc!compilers-sender
  2. From: scott@bbx.basis.com (Scott Amspoker)
  3. Newsgroups: comp.compilers
  4. Subject: Re: constant folding at parse time
  5. Keywords: parse, attribute
  6. Message-ID: <92-08-124@comp.compilers>
  7. Date: 20 Aug 92 15:41:14 GMT
  8. References: <92-08-040@comp.compilers> <92-08-097@comp.compilers>
  9. Sender: compilers-sender@iecc.cambridge.ma.us
  10. Reply-To: scott@bbx.basis.com (Scott Amspoker)
  11. Organization: BASIS International, Ltd., Albuquerque NM USA
  12. Lines: 28
  13. Approved: compilers@iecc.cambridge.ma.us
  14.  
  15. markh@csd4.csd.uwm.edu (Hunk) writes:
  16. >A expression evaluation routine I wrote for an expression parser in a
  17. >recently released assembler (C-expression syntax is handled) is set up in
  18. >such a way that all constant subexpressions will be reduced to leaf nodes
  19. >during parsing.  The question about whether a given expression is constant
  20. >or not doesn't even arise because it's already been handled by the parser.
  21. >Basically, if the expression tree returned by the parser is a leaf node
  22. >then it's a constant, otherwise it's not.
  23.  
  24. It all depends on what you call a constant.  The address of a global
  25. object is a constant and may be used in an initializer list:
  26.  
  27.    char c[10];
  28.    char *cp = &c[2];
  29.  
  30. The address of c[2] is a constant but cannot be folded by the compiler.
  31. Because of this, we have had to use a flag in a parse tree node to
  32. indicate the 'constant' status of the sub-expression.
  33.  
  34. -- 
  35. Scott Amspoker, Basis International, Albuquerque, NM
  36. scott@bbx.basis.com
  37. [I've worked with compilers that considered a constant to be a numeric
  38. offset plus an optional static symbol address.  This can be very convenient
  39. for generating addressing code. -John]
  40. -- 
  41. Send compilers articles to compilers@iecc.cambridge.ma.us or
  42. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  43.