19-Soft-B17 Programming Languages, Semantics and Implementation Exam A, Exams of Technology

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

2024/2025

Available from 06/05/2025

nicky-jone
nicky-jone 🇮🇳

3.1

(39)

28K documents

1 / 144

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
19-Soft-B17 Programming Languages,
Semantics and Implementation Exam
A
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
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download 19-Soft-B17 Programming Languages, Semantics and Implementation Exam A and more Exams Technology in PDF only on Docsity!

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

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

Semantics and Implementation Exam

A

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.

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

A

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?

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

A

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

Semantics and Implementation Exam

A

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