PLC Revision Exam Papers Flashcards
What is the role of Lexing in the compilation of a program?
Lexing is the process of converting an input string into a sequence of tokens
What is the role of Parsing in the compilation of a program?
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.
What is the role of Semantic Analysis in the compilation of a program?
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.
What is the role of Optimisation in the compilation of a program?
Increasing the efficiency of the program without changing the semantics.
What is Strong Typing?
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.
What is Weak Typing?
Languages that use Weak Typing do not always prevent errors but use types for compilation purposes such as memory layout.
Define the Concept of Progress and Preservation:
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.
What is the difference between type checking and type inference?
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.
What are some benefits of using formal semantics over compilers?
- The compiler could be implemented incorrectly, whereas formal semantics cannot be subject to implementation problems
- Formal semantics can give universal documentation for all other compilers to abide by
- Formal semantics can cover every edge-case, whereas a compiler’s type checker is only as good as the programs you write.
What is the main difference between shared variable and message-passing approaches to concurrent programming?
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.
Explain the difference between Asynchronous and Synchronous Communication:
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.
What is meant by an inductively defined typing relation for a programming language?
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.
What is the main difference between livelock and deadlock?
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.
What does the volatile keyword do in Java?
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.
Explain what is meant by small-step operational semantics of a programming language:
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’.