Ch1

It is not yet clear to what extent, and in what problem domains, we can expect compilers to discover good algorithms for problems stated at a very high level of abstraction. In any domain in which the compiler cannot find a good algorithm, the programmer needs to be able to specify one explicitly.

Q/A

What distinguishes the front end of a compiler from the back end?

What is the purpose of a compiler’s symbol table?

What is the difference between static and dynamic semantics?

Semantic Analysis

Semantic analysis is the discovery of meaning in a program. The semantic analysis phase of compilation recognizes when multiple occurrences of the same identifier are meant to refer to the same program entity, and ensures that the uses are consistent.

In most languages, the semantic analyzer tracks the types of both identifiers and expressions, both to verify consistent usage and to guide the generation of code in later phases.

To assist in its work, the semantic analyzer typically builds and maintains a symbol table data structure that maps each identifier to the information known about it. Information such as identifier’s type, internal structure, and scope.

Static vs Dynamic Semantic Analysis

semantic rules checked at compile time or runtime.

Example rules checked at runtime:

  • variables are never used in an expression unless they have been given a value.
  • Pointers are never dereferenced unless they refer to a valid object.
  • Array subscript expressions lie within the bounds of the array.
  • Arithmetic operations do not overflow.

For dynamic semantic rules, compiler will often produce code to perform appropriate checks at run time, aborting the program or generating an exception if one of the checks then fails.

(undefined behavior in C) Some rules, unfortunately may be unacceptably expensive or impossible to enforce, and the language implementation may simply fail to check them. In Ada, a program that breaks such a rule is said to be erroneous; in C its behavior is said to be undefined.

(Annotations/Attributes): Nodes in AST are annotated with useful information, such as pointers from identifiers to their symbol table entries. The annotations attached to a particular node are known as its attributes.

Created Aug 28, 2019 // Last Updated Oct 7, 2019

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?