You are on page 1of 7

KAMPALA INTERNATIONAL UNIVERSITY

(Western Campus)

Name: Kitaka Salim

REG No: BCS/0001/152/DU

Course unit: Compiler Construction

Lecturer: Mr. PAUL


Question
 Discuss the computational theory and semantics of
programming languages
 Characteristics of a good compiler
In programming language theory, semantics is the field concerned with the rigorous
mathematical study of the meaning of programming languages. It does so by evaluating the
meaning of syntactically legal strings defined by a specific programming language, showing the
computation involved. In such a case that the evaluation would be of syntactically illegal strings,
the result would be non-computation. Semantics describes the processes a computer follows
when executing a program in that specific language. This can be shown by describing the
relationship between the input and output of a program, or an explanation of how the program
will execute on a certain platform, hence creating a model of computation.

In theoretical computer science and mathematics, the theory of computation is the branch that deals
with how efficiently problems can be solved on a model of computation, using an algorithm. The field is
divided into three major branches: automata theory and language, computability theory, and
computational complexity theory, which are linked by the question: "What are the fundamental
capabilities and limitations of computers?" In order to perform a rigorous study of computation,
computer scientist’s work with a mathematical abstraction of computers called a model of computation.
There are several models in use, but the most commonly examined is the Turing machine.[2] Computer
scientists study the Turing machine because it is simple to formulate, can be analyzed and used to prove
results, and because it represents what many consider the most powerful possible "reasonable" model
of computation (see Church–Turing thesis).[3] It might seem that the potentially infinite memory
capacity is an unrealizable attribute, but any decidable problem[4] solved by a Turing machine will
always require only a finite amount of memory. So in principle, any problem that can be solved
(decided) by a Turing machine can be solved by a computer that has a finite amount of memory.

Formal semantics, for instance, helps to write compilers, better understand what a program is doing and
to prove, e.g., that the following if statement

if 1 = 1 then S1 else S2 has the same effect as S1 alone.

The field of formal semantics encompasses all of the following:

The definition of semantic models

The relations between different semantic models

The relations between different approaches to meaning

The relation between computation and the underlying mathematical structures from fields such as logic,
set theory, model theory, category theory, etc.

It has close links with other areas of computer science such as programming language design, type
theory, compilers and interpreters, program verification and model checking.

Some variations of formal semantics include the following:


Action semantics is an approach that tries to modularize denotational semantics, splitting the
formalization process in two layers (macro and microsemantics) and predefining three semantic entities
(actions, data and yielders) to simplify the specification;

Algebraic semantics is a form of axiomatic semantics based on algebraic laws for describing and
reasoning about program semantics in a formal manner;

Attribute grammars define systems that systematically compute "metadata" (called attributes) for the
various cases of the language's syntax. Attribute grammars can be understood as a denotational
semantics where the target language is simply the original language enriched with attribute annotations.
Aside from formal semantics, attribute grammars have also been used for code generation in compilers,
and to augment regular or context-free grammars with context-sensitive conditions;

Categorical (or "factorial") semantics uses category theory as the core mathematical formalism;

Concurrency semantics is a catch-all term for any formal semantics that describes concurrent
computations. Historically important concurrent formalisms have included the Actor model and process
calculi; Game semantics uses a metaphor inspired by game theory.

Predicate transformer semantics, developed by Edsger W. Dijkstra, describes the meaning of a program
fragment as the function transforming a postcondition to the precondition needed to establish it.

For a variety of reasons, one might wish to describe the relationships between different formal
semantics. For example:

To prove that a particular operational semantics for a language satisfies the logical formulas of an
axiomatic semantics for that language. Such a proof demonstrates that it is "sound" to reason about a
particular (operational) interpretation strategy using a particular (axiomatic) proof system.

To prove that operational semantics over a high-level machine is related by a simulation with the
semantics over a low-level machine, whereby the low-level abstract machine contains more primitive
operations than the high-level abstract machine definition of a given language. Such a proof
demonstrates that the low-level machine "faithfully implements" the high-level machine.

It is also possible to relate multiple semantics through abstractions via the theory of abstract
interpretation.

Automata theory is the study of abstract machines (or more appropriately, abstract 'mathematical'
machines or systems) and the computational problems that can be solved using these machines. These
abstract machines are called automata. Automata comes from the Greek word (Αυτόματα) which
means that something is doing something by itself. Automata theory is also closely related to formal
language theory, as the automata are often classified by the class of formal languages they are able to
recognize. An automaton can be a finite representation of a formal language that may be an infinite set.
Automata are used as theoretical models for computing machines, and are used for proofs about
computability.

Language theory is a branch of mathematics concerned with describing languages as a set of operations
over an alphabet. It is closely linked with automata theory, as automata are used to generate and
recognize formal languages. There are several classes of formal languages, each allowing more complex
language specification than the one before it, i.e. Chomsky hierarchy, and each corresponding to a class
of automata which recognizes it. Because automata are used as models for computation, formal
languages are the preferred mode of specification for any problem that must be computed.

Computability theory deals primarily with the question of the extent to which a problem is solvable on a
computer. The statement that the halting problem cannot be solved by a Turing machine is one of the
most important results in computability theory, as it is an example of a concrete problem that is both
easy to formulate and impossible to solve using a Turing machine. Much of computability theory builds
on the halting problem result.

Computability theory is closely related to the branch of mathematical logic called recursion theory,
which removes the restriction of studying only models of computation which are reducible to the Turing
model. Many mathematicians and computational theorists who study recursion theory will refer to it as
computability theory.

A representation of the relation among complexity classes

Complexity theory considers not only whether a problem can be solved at all on a computer, but also
how efficiently the problem can be solved. Two major aspects are considered: time complexity and
space complexity, which are respectively how many steps does it take to perform a computation, and
how much memory is required to perform that computation.

To simplify this problem, computer scientists have adopted Big O notation, which allows functions to be
compared in a way that ensures that particular aspects of a machine's construction do not need to be
considered, but rather only the asymptotic behavior as problems become large. So in our previous
example we might say that the problem requires O steps to solve.

Perhaps the most important open problem in all of computer science is the question of whether a
certain broad class of problems denoted NP can be solved efficiently. This is discussed further at
Complexity classes P and NP, and P versus NP problem is one of the seven Millennium Prize Problems
stated by the Clay Mathematics Institute in 2000. The Official Problem Description was given by Turing
Award winner Stephen Cook.

Models of computation

Aside from a Turing machine, other equivalent (See: Church–Turing thesis) models of computation are in
use.
Lambda calculus

A computation consists of an initial lambda expression (or two if you want to separate the function and
its input) plus a finite sequence of lambda terms, each deduced from the preceding term by one
application of Beta reduction.

Combinatory logic: is a concept which has many similarities to λ -calculus, but also important differences
exist (e.g. fixed point combinatory Y has normal form in combinatory logic but not in λ -calculus).
Combinatory logic was developed with great ambitions: understanding the nature of paradoxes, making
foundations of mathematics more economic (conceptually), eliminating the notion of variables (thus
clarifying their role in mathematics).

μ-recursive functions

a computation consists of a mu-recursive function, i.e. its defining sequence, any input value(s) and a
sequence of recursive functions appearing in the defining sequence with inputs and outputs. Thus, if in
the defining sequence of a recursive function if the functions g and h appear, then terms of the form
'g(5)=7' or 'h(3,2)=10' might appear. Each entry in this sequence needs to be an application of a basic
function or follow from the entries above by using composition, primitive recursion or μ recursion. For
instance if f , then for 'f(5)=3' to appear, terms like 'g(5)=6' and 'h(5,6)=3' must occur above. The
computation terminates only if the final term gives the value of the recursive function applied to the
inputs.

Markov algorithm

A string rewriting system that uses grammar-like rules to operate on strings of symbols.

Register machine

Is a theoretically interesting idealization of a computer. There are several variants. In most of them, each
register can hold a natural number (of unlimited size), and the instructions are simple (and few in
number), e.g. only decrementation (combined with conditional jump) and incrementation exist (and
halting). In addition to the general computational models, some simpler computational models are
useful for special, restricted applications. Regular expressions, for example, specify string patterns in
many contexts, from office productivity software to programming languages.

Different models of computation have the ability to do different tasks. One way to measure the power
of a computational model is to study the class of formal languages that the model can generate; in such
a way to the Chomsky hierarchy of languages is obtained.

Qualities of a Good Compiler


Correctness (does it preserve meaning -not as easy as it sounds but it is very important!). The meaning
of sentences must be preserved

Compiles quickly (complexity of compiling program O(n log n) ... remember bootstrapping!)

Output execution speed (how fast is the output code?)

Output footprint (how large is the code how much memory does it use?)

Separate compilation (relocatable code, linking)

Use friendly front-end: good error recovery.

Debugging facilities.

Cross language calls -- interface compatibilities.

Understandable and correct optimizations.Compiler: A compiler is a program that accepts a program


written in a High Level Language and produces an object (low-level) program.The compilation can be
done in two parts: Analysis and Synthesis.

In Analysis part the source program is read and broken down into constituent pieces. The syntax and
the meaning of the source string is determined and then an intermediate code is created from input
source program.

In Synthesis part this intermediate form of the source language is taken and converted into an
equivalent target program. During this process if certain code has to be optimized for efficient execution
then the required code is optimized.

Robust: wrong input is the common case– compilers and interpreters can’t just crash on wrong
input– they need to diagnose all kinds of errors safely and reliably
Efficient: resource usage should be minimal in two ways– the process of compilation or
interpretation itself insufficient– the generated code is efficient when interpreted
Usable: integrate with environment, accurate feedback– work well with other tools (editors,
linkers, debuggers, . . . )– descriptive error messages, relating accurately to source

The compiler itself must be bug-free.

It must generate correct machine code

The generated machine code must run fast

The compiler itself must run fast.

The compiler must be portable.

It must give good diagnostics and error messages.


The generated code must work well with existing debuggers

It must have Consistent optimization.

The good compiler compiles the a large amount code in less time.

The good compiler requires less amount of memory space to compile the source language.

The good compiler can compile only the modified code segment if frequent modifications are required
in the source program

While handling the hardware interrupts the good compilers interact closely with operating system.

REFERENCES

Michael Sipser (2013). Introduction to the Theory of Computation 3rd. Cengage Learning. ISBN 978-1-
133-18779-0. central areas of the theory of computation: automata, computability, and complexity.
(Page 1)

Andrew Hodges (2012). Alan Turing: The Enigma (THE CENTENARY EDITION). Princeton University Press.
ISBN 978-0-691-15564-7.

Rabin, Michael O. (June 2012). Turing, Church, Gödel, Computability, Complexity and Randomization: A
Personal View.

Donald Monk (1976). Mathematical Logic. Springer-Verlag. ISBN 9780387901701.

You might also like