Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1 Which of the following statements are true? I) Pattern matching and s

ID: 3826685 • Letter: Q

Question

Question 1

Which of the following statements are true?

I)  Pattern matching and string/text algorithms (e.g., substring matching, regular expression matching, longest common subsequence algorithms) are commonly used within the scanner portion of a language compiler or interpreter.

II) Parsers convert program text into tokens for use by a scanner.

III) Regular expressions describe context free grammars.

IV) LALR(1) parsers use "look-ahead" to simplify parser implementation while improving memory usage and performance. However, there exist LR(1) languages/grammars that are not parseable with LALR parsers.

V) An LR(1) parser is an LR(k) parser for k=1, i.e. with a single lookahead terminal. LR parsers can recognize any deterministic context-free language in linear-bounded time i.e. O(n).

Question 1 options:

a-

II and III

b-

I and V

c-

I, IV, and V

d-

I and III

e-

IV and V

Question 2

Which of the following statements are true?

I) An LR parser (Left to right, Rightmost derivation parser) is a type of shift-reduce parser. This parser has the potential of recognizing all deterministic context-free languages and can produce both left and right derivations of statements encountered in the input file.

II) LR parsers have historically required more memory to implement compared to LL parsers for the same language.

III) Lookahead establishes the maximum number of incoming tokens that a parser can use to decide which rule to apply. Lookahead for LL and LR parsers is often explicitly indicated by affixing the lookahead to the algorithm name in parentheses, such as LALR(1) meaning exactly one lookahead token is used.

IV) Backtracking is a general algorithm for finding all (or some) solutions to constraint satisfaction problems. Such algorithms incrementally build candidates to the solutions, and abandon each partial candidate as soon as it determines the candidate cannot possibly be completed to a valid solution.

V) Not every language recognizable by an LL(1) parser is recognizable by an LR(1) parser.

Question 2 options:

a-

I, II, III, IV, and V

b-

II and III

c-

I, II, III, and IV

d-

I, III, and IV

e-

only II

Question 3

Which of the following statements are true?

I) Dynamic dispatch is the process of selecting which implementation of a polymorphic operation (method or function) to call at run time. Dynamic dispatch contrasts with static dispatch in which the implementation of a polymorphic operation is selected at compile-time.

II) Dynamic dispatch is often used in object-oriented languages when different classes contain different implementations of the same method due to common inheritance. C++ virtual member functions are an example of dynamic dispatch.

III) Dynamic dispatch is a technique for avoiding the fragile base class problem.

IV) C++ compilers typically implement dynamic dispatch with a data structure called a vtable that defines the member function invocation to member function implementation mapping for a given class. Instances of C++ classes that define or inherit one or more virtual member functions store a pointer to a vtable as part of their instance data.

Question 3 options:

a-

I, II, III, and IV

b-

I, II, and III

c-

only II

d-

I, II, and IV

e-

II, III, and IV

Question 4

Which of the following statements are true?

I) A function or expression is said to have a side effect if, in addition to returning a value, it also modifies some state or has an observable interaction with calling functions or the outside world. For example, a function might modify a global variable, raise an exception, or write data to a file. Understanding and debugging a function with side effects requires knowledge about the context and order of evaluation.

II) In functional programming, side effects are typically avoided. For example, functional languages such as Standard ML, Scheme, and Scala do not restrict side effects, but it is customary for programmers to avoid them.

III) The use of side effects simplifies concurrent/parallel programming and code execution.

IV) Assembly language programmers must be aware of hidden side effects — instructions that modify parts of the processor state which are not mentioned in the instruction's mnemonic. A classic example of a hidden side effect is an arithmetic instruction that implicitly modifies condition codes (a hidden side effect) while it explicitly modifies a register (the overt effect).

Question 4 options:

a-

I, II, and IV

b-

I, II, III, and IV

c-

I and II

d-

I, II, and III

Question 5

Which of the following statements are true?

I) In object-oriented programming, an iterator is used to traverse a container/collection and access the container's elements. The iterator pattern decouples algorithms from containers.

II) Use of immutable variables prevents side-effects and enables safe aliasing of references.

III) First-class functions may be passed as arguments to other functions, returned as the values from other functions, and may be assigned to variables or stored in data structures.

IV) First-class functions are a necessity for the functional programming style. A simple usage example is the map function, which takes, as its arguments, a function and a list, and returns the list formed by applying the function to each member of the list. To implement map, it must be possible to pass a function (or at least a pointer to a function) as an argument.

V) The C standard library function, qsort(), is an example of using a first class function in a language that is not generally considered to be a "functional" programming language.

Question 5 options:

a-

I and II

b-

II, III, and IV

c-

I, II, and III

d-

I, II, III, and IV

e-

I, II, III, IV, and V

a-

II and III

b-

I and V

c-

I, IV, and V

d-

I and III

e-

IV and V

Explanation / Answer

Question 1:

I)Pattern matching and string/text algorithms are done by the lexical analyzer (also called as scanner) of the compiler. Scanner converts the input into the tokens using predefined patterns.

Answer:True

2)Parsers are also called as Syntax analyzer. Tokens are produced by Lexical analyzer and then passed to parsers. Parsers takes the tokens and converts them into parse tree.

Answer: false

3)Regular language is generated by Regular Language and Context free grammars generate Context free grammar.

Answer:false

4)LALR Parsers are look ahead LR parsers. They use look ahead to simplify the parser implementation. LALR are less powerful than LR parsers but more powerful than SLR parsers. Therefore, there exists some LR(1) grammars that are not parseable with LALR parsers.

Answer:true

5)LR(k) parser has ‘k’ look ahead symbols. So, LR(1) has one look ahead symbol.

Answer:true

Thus, the Correct option is I, IV, and V.

Question 2:

1)LR parses guarantees to handle CFG in linear time.

Answer:true

2)LR parsers can handle huge range of languages and grammars in comparison to LL parsers. LL parser takes less memory than LR parsers.

Answer:true

3)Look ahead means the future symbols that the parser can handle. Generally, look ahead is explicitly provided with the parser name, such as LL(k) means k look ahead symbol.

Answer:true

4)Backtracking follows all possible path to find the solution. It rejects the path that will not lead to valid solution.

Answer:true

5)LL(1) languages are proper subset of LR(1) languages.

Answer:true

Thus, the correct option is I, II, III, IV, and V.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote