PLC Revision Exam Papers Flashcards

1
Q

What is the role of Lexing in the compilation of a program?

A

Lexing is the process of converting an input string into a sequence of tokens

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the role of Parsing in the compilation of a program?

A

Parsing is the process of converting a sequence of tokens into an AST representation of a program by matching against the rules of the language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the role of Semantic Analysis in the compilation of a program?

A

Performing type checking on the produced AST, checking that the scope of all the variables are sound and checking if accesses to arrays are within their defined bounds.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the role of Optimisation in the compilation of a program?

A

Increasing the efficiency of the program without changing the semantics.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Strong Typing?

A

Languages that use Strong typing check the use of data to prevent program errors. Strong typing prevents access to private data and stops the programmer from corrupting memory and crashing the machine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Weak Typing?

A

Languages that use Weak Typing do not always prevent errors but use types for compilation purposes such as memory layout.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define the Concept of Progress and Preservation:

A

Progress exists if ⊢E:TE’EE’E is a value V
Preservation exists if ⊢E:TE’EE’⊢E’:T

Progress ensures that a well-typed program can always move forward or is finished.
Preservation ensures that a well-typed program remains well-typed after each step of execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between type checking and type inference?

A

Type inference has no types in variable declaration; the type is either inferred from the usage of the variable or by fixed naming schemes. Type Checking requires explicit type declarations by the programmer, while type inference infers types based on the code context, reducing the need for explicit type declaration. Type Checking can lead to more verbose code since types must be declared.
Type Inference can lead to more concise code as the compiler determines types automatically. Errors are caught based on the declared types during type checking. Errors are caught based on the inferred types and how they are used in type inference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some benefits of using formal semantics over compilers?

A
  1. The compiler could be implemented incorrectly, whereas formal semantics cannot be subject to implementation problems
  2. Formal semantics can give universal documentation for all other compilers to abide by
  3. Formal semantics can cover every edge-case, whereas a compiler’s type checker is only as good as the programs you write.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the main difference between shared variable and message-passing approaches to concurrent programming?

A

The main difference is that message passing techniques do not use locks or the critical section, thus avoiding deadlocks. Moreover , we cannot use share media for machines running on different machines, so message passing is usually used for that.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain the difference between Asynchronous and Synchronous Communication:

A

In synchronous communications, a thread sends a signal to another thread and enters a waiting state in order to not be scheduled any further before the signal is received. In Asynchronous communication, a thread sends a signal, and continues its execution without waiting for the signal to be received.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is meant by an inductively defined typing relation for a programming language?

A

An inductively defined typing relation for a programming language specifies how expressions are assigned types using a set of rules. These rules, presented as typing judgments, build up the types of complex expressions from simpler ones. In the context of the Mat language, this involves defining how to type matrix and vector operations based on the given grammar and semantics. This ensures that every valid expression can be systematically assigned a type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the main difference between livelock and deadlock?

A

Deadlock involves processes that are stuck and not progressing due to waiting for resources, while livelock involves processes that are actively changing states but still not making any progress.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the volatile keyword do in Java?

A

The volatile keyword ensures that changes to a variable are immediately visible to all threads. When a variable is declared as volatile, the Java Memory Model ensures that any thread reading the variable will see the most recently written value by any other thread.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain what is meant by small-step operational semantics of a programming language:

A

Small step semantics describe every step in computation of some term, until it reaches a value. If there exists a term E and a step in computation to reduce to term E’ (or some value), it is written as E → E’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly