0% found this document useful (0 votes)
2 views

CSC 407 tutorial

The document emphasizes the importance of understanding programming languages for computer professionals, highlighting the need to transition between languages and grasp their similarities. It outlines essential competencies related to programming languages, including linguistic aspects, implementation costs, architectural influences, and compilation techniques. Additionally, it provides a comprehensive set of tutorials and homework assignments aimed at deepening knowledge about abstract machines, programming language descriptions, and characteristics of various programming paradigms.

Uploaded by

Timti Hanson
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CSC 407 tutorial

The document emphasizes the importance of understanding programming languages for computer professionals, highlighting the need to transition between languages and grasp their similarities. It outlines essential competencies related to programming languages, including linguistic aspects, implementation costs, architectural influences, and compilation techniques. Additionally, it provides a comprehensive set of tutorials and homework assignments aimed at deepening knowledge about abstract machines, programming language descriptions, and characteristics of various programming paradigms.

Uploaded by

Timti Hanson
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

An important skill for the good computer professional or searcher is to know how to move from one

language to another, how to design and to learn new ones with naturalness and speed. This
competence is not obtained by learning many different languages from scratch. Programming
languages, like natural languages, have their similarities, analogies and they inherit characteristics
from each other.

It is for these reasons that a course on the general aspects of programming languages is, throughout
the world, a key step at advanced level for a computing professional everywhere! The fundamental
competences which a computing professional must possess about programming languages are of at
least four types:

• Some aspects that are properly considered linguistic.


• Knowledge of how language constructs can be implemented and the relative cost of these
implementations.
• Knowledge of those architectural aspects influencing implementation.
• Compilation techniques.

I. Tutorials
1. Describe the differences between the interpretative and compiled implementations of a
programming language, emphasizing the advantages and disadvantages.
2. Assume you have available an already-implemented abstract machine, C, how could you use
it to implement an abstract machine for another language, L?
3. What are the advantages in using an intermediate machine for the implementation of a
language?
4. Give at least three important differences between imperative and functional programming
paradigm.
5. Can a language combine functional and imperative programming features? How?
6. What is a type system? What is the purpose of a type system?
7. What does it mean that a term is syntactically correct? What does it mean that a term is
well-typed?
8. What is the relationship between typing rules and evaluation rules?
9. What properties constitute soundness of a type system? Explain each of them.
10. Explain the notions of explicit and implicit typing. Give examples of languages.
11. Explain the notions of static and dynamic typing. Give examples of languages.
12. What is a record (struct) type? Give examples in C++ and in Java.
13. What is a data (enum) type? Give examples in C++ and in Java.
14. What is a polymorphic function? Give an example of such a function. Explain the advantages
of writing polymorphic code.
15. What is a type class? How can it be used? Give an example.
16. Name the main ideas of object-oriented programming.
17. What is a class in OO programming? What is an object in OO programming?
18. Describe the three characteristic features of object-oriented languages.
19. What is the difference between a class variable and an instance variable?
20. What is multiple inheritance?
21. What is a polymorphic variable?
22. What is an overriding method?
23. Describe a situation where dynamic binding is a great advantage over its absence.
24. What is a virtual method?
25. What is an abstract method? What is an abstract class?
26. What is a nesting class?
27. What is the message protocol of an object?
28. Briefly describe the listed design issues: exclusivity of objects, subclasses and subtypes, type
checking and polymorphism, single and multiple inheritance, dynamic binding, explicit or
implicit deallocation of objects, and nested classes.
29. From where can C++ objects be allocated?
30. How are C++ heap-allocated objects deallocated?
31. How are C++ heap-allocated objects deallocated?
32. Are all C++ subclasses subtypes? If so, explain. If not, why not?
33. Under what circumstances is a C++ method call statically bound to a method?
34. What drawback is there to allowing designers to specify which methods can be statically
bound?
35. What are the differences between private and public derivations in C++?
36. What is a friend function in C++ ?
37. What is a pure virtual function in C++ ?
38. How are parameters sent to a superclass’s constructor in C++?
39. Programming in a functional language consists of building definitions and using the
computer to evaluate expressions
a. True or false: “a characteristic feature of functional programming is that if an
expression possesses a well-defined value, then the order in which a computer may
carry out the evaluation does not affect the outcome.
b. True or false: “the meaning of an expression is its value and the task of the
computer is simply to obtain it”.
c. True or false: “expressions in a functional language can be constructed,
manipulated and reasoned about, like any other kind of mathematical ex-pression,
using more or less familiar algebraic laws”.
d. Square(x)=x*x. Using ML language, write the function square. Do the same with
functions min(x,y), max(x,y), and quad using square function. Define the function
c_area that computes the area of a circle given the radius r. Use pi=22/7.
40. Reduction in functional programming
a. Consider the function square that you wrote before. Evaluate the expression
square(2+2). Give precisions on the mathematical rules you use at each step. How
many reduction can you have for that expression?
b. Count the number of different ways square(square(2+2)) can be reduced to normal
form (I.e result).
c. Imagine a language of expressions for representing integers defined by the syntax
rules: (i) zero is an expression; (ii) if e is an expression, then so are (succ e) and (pred
e). An evaluator reduces expressions in this language by applying the following rules
repeatedly until no longer possible: ( succ (pred e)) => e (succ1) and (pred ( succ e) )
=> e (pred1).
i. Simplify the expression ( succ (pred ( succ (pred (pred zero))))).
ii. In how many ways can the reduction rules be applied to this expression?
iii. Do they all lead to the same final result?
iv. Prove that the process of reduction must terminate for all given expressions.
(Hint: Define an appropriate notion of expression size, and show that
reduction does indeed reduce size.)
v. Suppose an extra syntactic rule is added to the language: (iii) if e1 and e2 are
expressions, then so is (add e1 e2). The corresponding reduction rules are:
 (add zero e2) => e2
 (add (succ e1) e2) => (succ (add e1 e2))
 (add (pred e1) e2) => (pred ( add e1 e2))
vi. Simplify the expression: (add (succ (pred zero)) zero).
vii. Count the number of different ways the reduction rules can be applied to
the above expression.
viii. Do they always lead to the same final result?
41. True or false: The most important kind of value in functional programming is a function
value.
42. True or false: A function f :: A --> B is said to take arguments in A and return results in B.
43. True or false: it is better to write (f x) rather than f x. Explain your answer.
44. True or false: There are many possible definitions for one and the same function. (Double,
min, max, … etc. ). For each listed function give 2 different ways they can be defined.
45.

II. Homework - Assignment


H1: Abstract machine and implementation.

Ref-Book: ”Programming languages: principles and paradigm, Maurizio Gabbrielli and Simone
Martini”

What is an abstract machine?

From figure 1 (The structure of an abstract machine), explain the concept of interpreter. Give the
role of any element of this architecture and explain how he work together.

The type of operation executed by the interpreter and associated data structures, fall into the
following categories:

1. Operations for processing primitive data;


2. Operations and data structures for controlling the sequence of execution of operations;
3. Operations and data structures for controlling data transfers;
4. Operations and data structures for memory management.

Using your knowledges from programming courses, how can you explain tis different operations?

Figure 1 below shows a conventional calculator. Identify and describe different parts of this
calculator.
Figure 1: conventional calculator

Any abstract machine can be implemented.

1. What are different type of implementation of machine abstraction?


2. What do you understand by purely interpreted implementation? Purely compiled
implementation?
3. What are key differences between the two concepts?

H2: How to describe a programming language and test it!

We identified three major areas to describe a language: grammar, semantics and pragmatics.

Consider this production rule, where ”=” represent the production symbol ”----- >”:

<SPL> = <Decl>+ <Exp> = <Exp> <Op2> <Exp> | <Exp-base>


<Decl> = <VarDecl> <Exp-base> = <Id> [<Field>]
| <FunDecl> | <Op1> <Exp>
| <ClassDecl> | <int>
<VarDecl> = ('var' | <Type>) <id> '=' <Exp> ';' | '\'' <char> '\''
<FunDecl> = <id> '(' [ <FArgs> ] ')' | 'False'
[ '::' <FunType> ] | 'True'
'{' <VarDecl>* Stmt+ '}' | '(' <Exp> ')'
<ClassDecl> = ['class'] <ClassId> | <FunCall>
'{' <VarDecl>* <FunDecl>* '}' | '[]'
<FunType> = <Type>* '->' <Type> | '(' <Exp> ',' <Exp> ')'
<Type> = <BasicType> | <ClassId>'(' <FArgs> ')'
| '(' <Type> ',' <Type> ')' | new <ClassId>'(' <FArgs> ')'
| '[' <Type> ']' | delete <Exp>
| <ClassId> <Field> = ( '.' 'hd' | '.' 'tl' | '.' 'fst' | '.' 'snd')+
| <Id> <FunCall> = <id> '(' [ <ActArgs> ] ')'
<BasicType> = 'Int' <ActArgs> = <Exp> [ ',' <ActArgs> ]
| 'Bool' <Op2> = '||' | '|' | '&&' | '&'
| 'Char' | '==' | '!=' | '<' | '>' | '<=' | '>='
| 'Void' | ':' | '&+' | '&-' | '&-&' | '<<' | '>>'
<FArgs> = <id> [',' <FArgs>] | '+' | '-'
<Stmt> = <VarDecl> | '*' | '/' | '%'
| 'if' '(' <Exp> ')' <Stmt> [ 'else' <Stmt> ] <Op1> = '!' | '-' | '(' <Type> ')' | '&' | '*'
| 'while' '(' <Exp> ')' <Stmt> <Int> = ['-' digit+] | ['-' '0x' digit+]
| <Exp> '=' <Exp> ';' <ClassId> = Alpha ( '_' | AlphaNum)*
| <FunCall> ';' <Id> = alpha ( '_' | alphaNum)*
| 'return' [<Exp>] ';'
| '{' <Stmt>* '}'

1. From the definition of a grammar, describe this grammar. Which type of grammar is it?
2. Write a piece of code (program) of more than 20 instructions that is recognized by the
language we obtain from this grammar.
3. Is this an imperative language? Explain your answer!!
H3: characteristics of programming paradigms

Type Features Framework Patterns Style Evolution of Languages?


Imperative 1. For general purpose Procedure/function Variables Top down Functional C,
programing call Instructions Explicit control flow (applicative) Pascal,
2. Easy to learn Sequence of Sequences State modification Procedural Python,
3. Portable code source instructions Selections Structured C++
4. Code reuse without Sep by step Iterations
rewriting it Procedure
5. Track the program flow. Functions
Object Oriented 1. Data Abstraction Classes (Data and Module Interaction Imperative C++
2. Encapsulation Method) Variable in a Messages Python
3. Inheritance Object module Java
4. Polymorphism Events State, Behavior C#
Assembly One to one translation Mnemonic Statements formats Instruction set of Specific to MIPS
Hardware dependent Opcode names processor processor Intelx86
System programming Operand type Operand Macros
orientation Operand order addressing
Special purpose Registers names Registers
Few abstraction Control statement Function call
Functional 1. Pure function Function call No variables No command
2. Recursion Function Recursion Side effect
3. Referential transparency decomposition Evaluation of
4. Functions are First-Class mathematical
and can be Higher-Order functions
5. Immutable variables No mutable data
Logical 1. Express knowledge Mathematical logic Variables Assertions Logic (inheritance) Prolog
2. Separate knowledge from Facts Logical Inferences Declarative SQL
use Rules Clauses (head and Questions
body) Unification

You might also like