CS 5363 Programming Languages & Compilers
Fall 2002 -- Review for Final Exam
Final Exam: Tuesday, 10 December,
8:00 - 10:45 pm
Main Topics for the Final Exam:
See homework:
Recursive-descent
parser.
Introductory semantic actions:
This means to insert extra code into a parser that will
carry out various tasks, including translation from one language to
another. The code can be placed into a recursive descent parser
(as we did it),
or it can be attached to each grammar rule to be automatically called
when the rule is used in a reduction (as would be done with the
books kind of LR parsers).
Here are some example programs:
Translator of arithmetic expressions to RPN:
.c,
.txt,
.html,
.ps,
.pdf.
.java,
.txt,
.ps,
.pdf.
Here is another example of semantic actions: an evaluator
of arithmetic expressions, producing a double:
.c
.txt,
.html,
.ps,
.pdf.
See homework:
Translating
Assignments.
Syntax-directed translation:
This is the method used in this course. We discussed this from
a theoretical point of view, based on the parse tree.
One attaches attributes (values) to each node of the tree.
Then the issue is how the attribute values are defined.
Synthesized attributes get their values from nodes
below the given node in the parse tree. Thus in the
terms of a recursive descent parser, these attributes come
as values returned by functions called during the parse.
These synthesized attributes are the most common ones and are
the ones we emphasized.
Inherited attributes are more complicated, and don't just
come from the children of a given node, but come from the parent
as well. In a recursive descent parser, one would pass a parameter
from the parent to the child to help give a value to an inherited
attribute. (Text, pp. 279-287.)
Semantic actions for while and other constructs:
See homework:
while,
if, relational, logical.
Run-time storage management: (Text, Chapter 9 (part).)
- Memory use at run time (code, static data, stack-allocated
data, heap-allocated data). (Text, p. 297.)
- Storage in old-fashioned Fortran, where all storage was static.
(Text, pp. 401-402.)
- Activation records for function calls and stack allocation.
(Text, pp. 398-399, pp. 404-409.)
- Levels of allocation in block-structured languages,
including especially Pascal. The use of a stack of
symbol tables at compile time. (Class notes.)
- The problem of dangling references. (Text, p. 409.)
- Heap allocation, using explicit calls, such as
malloc and free in C, or
new and delete in C++.
(See The C Programming Language
by Kernighan and Ritchie, pp. 185-188, for a discussion of a
simple malloc implementation that we discussed
in class.)
- Heap allocation, using garbage collection as in Java.
The mark-sweep algorithm. Reference counts to avoid
dangling references (that can cause run time crashes).
(Class notes.)
See homework:
Functions.
W-grammars: Formal semantics of progrmaming languages:
We covered the so-called W-grammars or 2-level grammars.
This material was pretty hard, so I guess I'll leave it off the final.
LR parsing:
- Use of LR action and goto tables to carry
out a shift-reduce parse, pushing alternating symbols and
state numbers on the stack. (Text, pp. 215-221.)
- LR(0) items, with the sets-of-items consturction, and
the closure and goto functions.
Construction of the parsing DFA, and its use to carry out
simple parses. (Text, pp. 221-228.)
- LR(1) items, with a new similar sets-of-items construction,
and similar closure and goto functions. (Text, pp. 230-232.)
- A specific example, showing a 10 state LR(1) parser
and a 7-state LR(0) parser for the same language.
(Text, pp. 233-236.)
Revision date: 2002-12-04.
(Please use ISO
8601, the International Standard.)