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