




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Explores classification of programming languages (procedural, object-oriented, functional, logic-based) and formal semantics (operational, denotational, axiomatic). Topics include grammar, parsing (LL, LR), syntax-directed translation, type systems, and memory models. Students analyze interpreter and compiler construction fundamentals, lambda calculus, and run-time environments.
Typology: Exams
1 / 144
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which programming paradigm emphasizes the use of functions without mutable state? A) Imperative B) Functional C) Object-Oriented D) Logic Answer: B Explanation: Functional programming focuses on pure functions and immutability, avoiding mutable state to facilitate reasoning about code and enable features like lazy evaluation. Question 2. What is the primary purpose of a formal syntax definition in programming languages? A) To specify the semantics of language constructs B) To define the structure and valid arrangement of language tokens C) To describe the execution behavior of programs D) To optimize compiler performance
Answer: B Explanation: Formal syntax, often defined using BNF or EBNF, specifies how tokens are arranged to form valid programs, ensuring syntactic correctness. Question 3. Which of the following best describes a parse tree? A) An abstract representation of program semantics B) A syntax tree that directly reflects the source code structure C) A tree used to optimize code during compilation D) A graph representing runtime program states Answer: B Explanation: A parse tree is a concrete syntax tree that shows the hierarchical structure of source code according to grammar rules, directly reflecting syntax. Question 4. Which semantic approach models program execution as a sequence of state transitions? A) Denotational semantics B) Operational semantics
Question 6. Which component of an abstract machine models the execution context during function calls? A) Heap B) Activation record (stack frame) C) Register set D) Finite automaton Answer: B Explanation: Activation records, stored in the call stack, contain information about function execution context, such as local variables and return addresses. Question 7. In denotational semantics, what mathematical concept is used to model recursive language constructs? A) Fixed points of continuous functions B) Finite automata C) Transition systems D) State machines Answer: A
Explanation: Recursive constructs are modeled using least fixed points of continuous functions over domains, capturing potentially infinite behaviors in a mathematical way. Question 8. Which Hoare triple correctly expresses the partial correctness of a program segment that assigns a value to a variable? A) {x > 0} x := x + 1 {x > 1} B) {True} if x > 0 then x := x + 1 {x > 0} C) {x = 5} x := x + 1 {x = 6} D) {x = 0} while x < 10 do x := x + 1 {x ≥ 10} Answer: C Explanation: The Hoare triple {x=5} x := x+1 {x=6} specifies that if x is initially 5, after assignment, x will be 6, correctly establishing partial correctness. Question 9. Which type system characteristic allows functions to operate on arguments of different types? A) Static typing B) Parametric polymorphism
A) LL parsing B) LR parsing C) Shift-reduce parsing D) Bottom-up parsing Answer: A Explanation: LL parsing is a top-down approach where the parser predicts productions and uses recursive procedures, suitable for recursive descent implementations. Question 12. Which formalism is used to specify the syntax of a programming language using a set of production rules? A) Automata theory B) Backus-Naur Form (BNF) C) Lambda calculus D) Turing machine Answer: B Explanation: BNF is a notation for defining context-free grammars, used to specify syntax rules of programming languages.
Question 13. Which semantic approach assigns mathematical functions to language constructs to define their meaning? A) Operational semantics B) Denotational semantics C) Axiomatic semantics D) Structural semantics Answer: B Explanation: Denotational semantics maps constructs to mathematical objects (functions), providing a compositional and mathematical view of program meaning. Question 14. Which property of operational semantics ensures that a program always produces a unique next state during execution? A) Non-determinism B) Determinism C) Termination D) Soundness Answer: B
Answer: C Explanation: Static type checking occurs during compilation, ensuring type correctness before program runs, which can prevent runtime errors. Question 17. Which data structure is primarily used to manage local variables and control information during function execution? A) Heap B) Stack (activation records) C) Queue D) Graph Answer: B Explanation: The call stack, via activation records, manages local variables, return addresses, and control flow during function calls. Question 18. Which concurrency model involves multiple processes communicating via message passing? A) Shared memory model B) Message passing model
C) Data parallelism D) Functional concurrency Answer: B Explanation: The message passing model uses explicit message exchanges between processes, common in distributed systems. Question 19. Which synchronization mechanism prevents multiple threads from accessing shared resources simultaneously? A) Semaphore B) Mutex (mutual exclusion lock) C) Barrier D) Condition variable Answer: B Explanation: Mutexes ensure mutual exclusion, allowing only one thread to access critical sections at a time. Question 20. Which concept in functional programming refers to functions that capture variables from their defining environment?
Question 22. Which exception handling mechanism involves catching exceptions to manage runtime errors? A) Try-catch blocks B) Hoare triples C) Static type checking D) Lazy evaluation Answer: A Explanation: Try-catch blocks are used to handle exceptions during program execution, allowing graceful error recovery. Question 23. Which class of languages is designed specifically for expressing domain-specific problems and often features specialized syntax and semantics? A) General-purpose languages B) Domain-Specific Languages (DSLs) C) Assembly languages D) Functional languages Answer: B
Explanation: DSLs are specialized languages tailored to particular application domains, enabling concise and expressive problem modeling. Question 24. Which phase in compiler design transforms an abstract syntax tree into machine code or intermediate representation? A) Semantic analysis B) Code generation C) Lexical analysis D) Optimization Answer: B Explanation: Code generation converts the intermediate representation, such as an AST, into target machine code or bytecode. Question 25. What is the primary difference between static and dynamic scoping? A) Static scoping uses run-time information, dynamic scoping uses compile- time information B) Static scoping determines variable bindings based on the program
Question 27. Which language feature allows a function to be passed as an argument or returned as a value? A) Encapsulation B) Higher-order functions C) Inheritance D) Static typing Answer: B Explanation: Higher-order functions can accept other functions as parameters or return them, enabling functional programming patterns. Question 28. In the context of language implementation, what is an intermediate code? A) Machine code generated directly from source code B) A platform-independent representation used between parsing and code generation C) The source code before compilation D) The final executable program Answer: B
Explanation: Intermediate code serves as a portable, abstract representation that facilitates optimization and target code generation. Question 29. Which type of analysis aims to prove that a program adheres to specified correctness properties? A) Syntax analysis B) Formal verification C) Lexical analysis D) Runtime profiling Answer: B Explanation: Formal verification involves mathematically proving that a program satisfies certain correctness criteria. Question 30. Which concept in language design involves defining a subset of constructs to simplify implementation and analysis? A) Language extensibility B) Language restriction C) Language subset or core language
A) Compositionality B) Soundness C) Completeness D) Determinism Answer: A Explanation: Compositionality means the meaning of complex expressions can be derived from their components' meanings, facilitating modular reasoning. Question 33. Which language implementation technique involves translating source code into an intermediate language before generating machine code? A) Interpretation B) Compilation with intermediate code C) Just-in-time compilation D) Direct interpretation Answer: B Explanation: Many compilers translate source code into an intermediate
language (e.g., bytecode), then perform further optimization and target code generation. Question 34. Which language feature enables an object to hide its internal data and only expose specific interfaces? A) Inheritance B) Encapsulation C) Polymorphism D) Abstraction Answer: B Explanation: Encapsulation restricts direct access to internal object data, promoting modularity and security. Question 35. In static semantics, what is the primary purpose of type inference? A) To check type correctness at runtime B) To automatically deduce types of expressions without explicit annotations C) To enforce dynamic typing rules