king@nsc.UUCP (06/20/84)
I have been considering the usage of attribute grammars in code generators. There are a few papers that mention the subject but I have not yet heard of any products available using this technique. Is there anyone out there that has worked with or knows of such a beast? Are there any studies comparing this method with more traditional methods re speed, efficiency? Does anyone else besides me care?
alan@allegra.UUCP (Alan S. Driscoll) (06/20/84)
> I have been considering the usage of attribute grammars in > code generators. There are a few papers that mention the > subject but I have not yet heard of any products available > using this technique. Is there anyone out there that has > worked with or knows of such a beast? Are there any studies > comparing this method with more traditional methods re > speed, efficiency? Does anyone else besides me care? I care! As a matter of fact, I'm currently writing a grammar-based code generator. Portability is one of my main goals, so I need a formalism that's powerful, easy to use, and readable. If you're concerned about the quality of the code generated, [2] suggests that using an attribute grammar compares favor- ably with more traditional approaches. Special cases are handled very elegantly by adding new productions, rather than cluttering up old code. This, and the general ease of writing an attribute grammar, encourage a more thorough description of the machine. Also, you never have the problem of fitting a square com- puter into a round generator. No assumptions about the architecture are hard-wired (unless you've hard-wired them into your IR). Since everything is explicit in the grammar, everything is negotiable. I've ported PCC several times. The code generation algo- rithm is full of assumptions about the machine, and these assumptions often get in the way. Also, PCC's code genera- tion templates are quite painful. (I'm talking about PCC2. PCC1 is absolutely gross. Take a look at 'table.c' some- time.) For the most part, orthogonality in the target machine's instruction set (which should make life easier!) just leads to redundancy in PCC's code generation templates, since PCC doesn't allow you to talk about sets of operations, but requires you to describe each one separately. Writing the templates gets tedious, and the machine description becomes cluttered and hard to read. So, at this point, I really think attribute grammars are the way to go. I'd like to hear more about what other people are doing. Alan S. Driscoll AT&T Bell Laboratories -- [1] R. S. Glanville and S. L. Graham, "A New Method for Compiler Code Generation," Conf. Record 5th ACM Symp. Principles of Programming Languages. [2] M. Ganapathi and C. N. Fischer, "Description-Driven Code Generation using Attribute Grammars," Conf. Record 9th ACM Symp. Principles of Programming Languages. -- Alan S. Driscoll AT&T Bell Laboratories