SLIDE 1
326 Chapter 8 Computer Languages As you can imagine, for a large program the number and complexity of the semantic records may become immense. The compiler must have rules for all types of expressions, control structures like if and for, function calls and much more. But, compilation is not a magic process; each step can be written down and straightforwardly explained.
Exercises for 8.1.3
- 1. Give a parse tree with semantic records for the statement Z = 2 + 2. Show the
assembly language translation that results.
- 2. Give a parse tree with semantic records for the statement C = 9 * 4 * 5. Show the
assembly language translation that results.
- 3. Why is a symbol table needed? Why is it that a constant or variable cannot be given an
address immediately, when its semantic record is created?
- 4. Give a set of semantic rules for generating semantic records. Your set should have
seven rules to correspond with the seven syntax rules.
8.1.4 Grammars for Fractal trees
Formal grammars have not just been applied to natural and computer languages. They have a wide range of applications throughout the arts and sciences. A wonderful applica- tion that merges art and science is the generation of artificial plants. Botanist Aristid Lin- dermeyer started working on artificial plants in the 1960s and from his work came a specialized set of grammars called L-systems. L-systems are used to model the growth of
- plants. Algebraic equations can model the rate of growth of single cells, tissues and stems,
but have a hard time with branching structures; as you can imagine from our parse trees, formal grammars can easily model the production of branches. An L-system is very similar to a formal grammar, with one major difference; the interpre- tation of the resulting language. Instead of treating the language as mathematical formulas
- r English sentences, we will interpret each string as a set of instructions for a drawing a
- figure. We will use Turtle graphics as we did in Chapter 3 to draw fractal trees, but this