Re: Simple constant folding in bison parser (Dale R. Worley)
Mon, 17 Aug 1992 19:25:22 GMT

          From comp.compilers

Related articles
Simple constant folding in bison parser (1992-08-05)
Re: Simple constant folding in bison parser (1992-08-10)
Re: Simple constant folding in bison parser (1992-08-17)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (Dale R. Worley)
Organization: MIT Dept. of Tetrapilotomy, Cambridge, MA, USA
Date: Mon, 17 Aug 1992 19:25:22 GMT
Keywords: yacc, attribute
References: 92-08-020 92-08-040 (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.

      [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

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

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.