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