Book contents
- Frontmatter
- Contents
- Preface
- 1 A modern approach to computing
- 2 Specifications I
- 3 Diagrams
- 4 Specifications II
- 5 PDL
- 6 Code generation
- 7 Verification
- 8 Examination of templates and target code
- 9 Abstract data types
- 10 The mathematical basis of abstract data types
- 11 Utilisation of existing programs
- 12 A small scale study – topological sorting
- Appendices
- References
- Index
6 - Code generation
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- 1 A modern approach to computing
- 2 Specifications I
- 3 Diagrams
- 4 Specifications II
- 5 PDL
- 6 Code generation
- 7 Verification
- 8 Examination of templates and target code
- 9 Abstract data types
- 10 The mathematical basis of abstract data types
- 11 Utilisation of existing programs
- 12 A small scale study – topological sorting
- Appendices
- References
- Index
Summary
In this chapter we address the issues of coding from a PDL into various real imperative programming languages. The PDL stage described in the previous chapter contains a complete (imperative) solution to the original problem so that the coding can now be finished without reference to the original problem. The intention in this chapter is to show that the final code generation can be accomplished using coding templates. Coding templates are shown for a variety of programming languages in common use.
Templates
Coding templates are stylised translations of each feature of a PDL. The methodical application of the templates to the PDL solution will yield the final code.
For any particular final coding language, a set of (coding) templates is created to translate each feature of the PDL in use. This means for example that every ‘if’ statement in the PDL is translated in the same way. Each time the ‘if’ statement is met it is coded using the same pattern or template. The templates are different for each different final coding language. They are chosen more for generality than for elegance or efficiency. There may well be features of a final coding language that are not used in any template. In this methodology these features will never be used. This may seem an unacceptable loss at first sight. However the experience of the authors is that the features which are not used in templates are those which are less widely used anyway or not universally supported or inconsistently supported and so their omission leads to more portable programs.
- Type
- Chapter
- Information
- Program Construction , pp. 88 - 154Publisher: Cambridge University PressPrint publication year: 1987