250+ TOP MCQs on Finite Automata and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Finite Automata”.

1. Which of the following statement is true for Dead State?
a) It cannot be reached anytime
b) There is no necessity of the state
c) If control enters no way to come out from the state
d) If control enters FA deads

Answer: c
Clarification: It is a rejecting state for if the control enters it reaches the dead end and cannot reach an accepting state.

2. Which of the following statement is true for Moore Machine?
a) Output depends on present state
b) Output depends on present input
c) Output depends on present state and present input
d) Output depends on present state and past input

Answer: a
Clarification: The definition states that moore machines output is determined by the current state only.

3. Which of the following statement is true for Mealy Machine?
a) Output depends on present state
b) Output depends on present input
c) Output depends on present state and present input
d) Output depends on present state and past input

Answer: c
Clarification: The definition states that its output is determined by current state and current input.

4. Which is true for in accessible state?
a) It cannot be reached anytime
b) There is no necessity of the state
c) If control enters no way to come out from the state
d) If control enters FA deads

Answer: a
Clarification: The very meaning of in accessible state is that it cannot be reached at any point of time.

5. In Mealy Machine O/P is associated with ____________
a) Present state
b) Next state
c) Input
d) None of the mentioned

Answer: b
Clarification: The definition states that its output is determined by current state and current input.

6. In Moore Machine O/P is associated with ____________
a) Present state
b) Next state
c) Input
d) None of the mentioned

Answer: a
Clarification: The definition states that moore machines output is determined by the current state only.

7. Which type of string is accepted by the following finite automata?
a) All string
b) Null string
c) No string
d) None of the mentioned

Answer: b
Clarification: Null strings are not accepted by finite automata.

8. Myhill-Nerode Theorem is used for __________
a) Minimization of DFA
b) Maximization of NFA
c) Conversion of NFA
d) Conversion of DFA

Answer: a
Clarification: Myhill–Nerode theorem provides a necessary and sufficient condition for a language to be regular. The Myhill–Nerode theorem can be generalized to trees. And used for minimization of DFA.

250+ TOP MCQs on Syntax Analyser and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Syntax Analyser”.

1. Select a Machine Independent phase of the compiler.
a) Syntax Analysis
b) Intermediate Code generation
c) Lexical Analysis
d) All of the mentioned

Answer: d
Clarification: All of them work independent of a machine.

2. A system program that combines the separately compiled modules of a program into a form suitable for execution?
a) Assembler
b) Compiler
c) Linking Loader
d) Interpreter

Answer: c
Clarification: A loader which combines the functions of a relocating loader with the ability to combine a number of program segments that have been independently compiled.

3. Which of the following system software resides in the main memory?
a) Text Editor
b) Assembler
c) Linker
d) Loader

Answer: d
Clarification: Loader is used to loading programs.

4. Output file of Lex is __________ the input file is Myfile.
a) Myfile.e
b) Myfile.yy.c
c) Myfile.lex
d) Myfile.obj

Answer: b
Clarification: This Produce the filr “myfile.yy.c” which we can then compile with g++.

5. Type checking is normally done during ____________
a) Lexical Analysis
b) Syntax Analysis
c) Syntax Directed Translation
d) Code generation

Answer: c
Clarification: It is the function of Syntax directed translation.

6. Suppose One of the Operand is String and other is Integer then it does not throw error as it only checks whether there are two operands associated with ‘+’ or not.
a) True
b) False

Answer: a
Clarification: Syntax analyser does not check the type of the operand.

7. In Short Syntax Analysis Generates Parse Tree.
a) True
b) False

Answer: a
Clarification: Short Syntax Analysis generates a parse tree.

8. By whom is the symbol table created?
a) Compiler
b) Interpreter
c) Assembler
d) None of the mentioned

Answer: a
Clarification: Symbol table is created by the compiler which contains the list of lexemes or tokens.

9. What does a Syntactic Analyser do?
a) Maintain Symbol Table
b) Collect type of information
c) Create parse tree
d) None of the mentioned

Answer: c
Clarification: Syntax analyzer will just create a parse tree. Semantic Analyzer checks the meaning of the string parsed.

10. Semantic Analyser is used for?
a) Generating Object code
b) Maintaining symbol table
c) Generating Object code & Maintaining symbol table
d) None of the mentioned

Answer: c
Clarification: Maintaining the Symbol Table for each block.
Source Program for Semantic Errors.
Collects Type Information for Code Generation.
Reporting compile-time errors in the code Generating the object code (e.g., assembler or intermediate code).

250+ TOP MCQs on Data Structure for Representing Parsing Table Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Data Structure for Representing Parsing Table”.

1. Compiler can diagnose __________
a) Grammatical errors only
b) Logical errors only
c) Grammatical and logical errors
d) None of the mentioned

Answer: a
Clarification: Only syntactical errors can be detected by the compiler.

2. A simple two-pass assembler does which of the following in the first pass?
a) It allocates space for the literals
b) Calculates total length of the program
c) Symbol table is built for the symbols and their value
d) All of the mentioned

Answer: d
Clarification: A two-pass assembler. Each pass scans the program, the first pass generates the symbol table and the second pass generates the machine code.

3. A system program that set-up an executable program in the main memory ready for execution is?
a) Assembler
b) Linker
c) Loader
d) Text editor

Answer: c
Clarification: A loader is the part of an operating system that is responsible for loading programs and libraries. It is important that with the starting of a program, as it places programs into memory and executes it.

4. A compiler is a program that ___________
a) Program is put into memory and executes it
b) Translation of assembly language into machine language
c) Acceptance of a program written in a high level language and produces an object program
d) None of the mentioned

Answer: c
Clarification: A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language, often having a binary form known as object code).

5. A programmer by mistake writes multiplication instead of division, such error can be detected by?
a) Compiler
b) Interpreter
c) Compiler or interpreter test
d) None of the mentioned

Answer: d
Clarification: No Logical errors can be detected.

6. The computer language generally translated to pseudocode is ___________
a) Assembly
b) Machine
c) Pascal
d) FORTRAN

Answer: a
Clarification: An assembly language (or assembler language) is a low-level programming language for a computer, or other programmable device, in which there is a very strong (generally one-to-one) correspondence between the language and the architecture’s machine code instructions.

7. A system program that combines separately compiled modules of a program into a form suitable for execution is?
a) Assembler
b) Linking Loader
c) Cross Compiler
d) None of the mentioned

Answer: b
Clarification: A loader which combines the functions of a relocating loader with the ability to combine a number of program segments that have been independently compiled into an executable program.

8. In which way a macro processor for assembly language can be implemented?
a) Independent two-pass processor
b) Independent one-pass processor
c) Processor put into pass 1 of a standard two pass assembler
d) All of the mentioned

Answer: d
Clarification: A general-purpose macro processor or general purpose preprocessor is a macro designed for string manipulation, macro definition.

9. Resolution of externally defined symbols is performed by ___________
a) Linker
b) Loader
c) Compiler
d) Interpreter

Answer: a
Clarification: A linker or link editor is a computer program that takes one or more object files generated by a compiler and combines them into a single executable file, library file, or another object file.

10. A shift reduce parser carries out the actions specified within braces immediately after reducing with the corresponding rule of grammar S—-> xxW ( PRINT “1”) S—-> y { print ” 2 ” } S—-> Sz { print ” 3 ” ) What is the translation of xxxxyzz using the syntax directed translation scheme described by the above rules?
a) 23131
b) 11233
c) 11231
d) 33211

Answer: a
Clarification: Initially 2 is printed then 3 then 1 3 1.

250+ TOP MCQs on Array Reference and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Array Reference”.

1. Which of the following correctly declares an array?
a) Int array[ 10]
b) int array
c) array{10}
d) array array[ 10]

Answer: a
Clarification: Correct declaration.

2. What is the index number of the last element of an array with 29 elements?
a) 29
b) 28
c) 0
d) Programmer-Defined

Answer: b
Clarification: The indexing in an array starts with zero hence we can say that the element.

3. Which of the following is a two-dimensional array?
a) array array[20][20]
b) int array[20][20]
c) int array[20, 20]
d) char array[20]

Answer: b
Clarification: Double dimensional arrays are declared in this format.

4. Which of the following correctly accesses the seventh element stored in tan?
a) tan[6]
b) tan[7]
c) tan(7)
d) tan

Answer: a
Clarification: The index no 6.

5. Which of the following gives the memory address of the first element in array tan?
a) tan[0]
b) tan
c) &tan
d) tan [1]

Answer: b
Clarification: The base address of the array is given by its name.

6. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?
a) The compiler would report an error
b) May stop working abruptly if data gets overwritten
c) None of the mentioned
d) The element will be set to 0

Answer: b
Clarification: It often happens that the program crashes.

7. What does the following declaration mean?

a) Pointer to an array
b) None of the mentioned
c) Array of 10 integers
d) Pointer to an array & Array of 10 integers

Answer: a
Clarification: Points to array.

8. What is the meaning of the following declaration?

a) Integer Array of size 20
b) None of the mentioned
c) Array of size 20
d) Array of size 20 that can have higher integer address

Answer: a
Clarification: Declaration of an array.

9. What will be the size of below array elements?

a) 21
b) 22
c) 20
d) 19

Answer: c
Clarification: The number in square brackets denotes size of an array.

10. What is meaning of the following?

a) Interger array of size 20 pointing to an integer Pointer
b) None of the mentioned
c) Array of integer pointer of size 20
d) All of the mentioned

Answer: c
Clarification: Array of pointers to integers.

250+ TOP MCQs on Non-Deterministic Finite Automata and Answers

Compilers Multiple Choice Questions on “Non-deterministic Finite Automata”.

1. NFAs are ________ DFAs.
a) Larger than
b) More expressive than
c) Less expressive than
d) Equally expressive as

Answer: a
Clarification: Because there is more number of states for an NDFA than for a DFA for a given expression.

2. An NFA’s transition function returns ________
a) A Boolean value
b) A state
c) A set of states
d) An edge

Answer: c
Clarification: A transition function Δ: Q × Σ → P (Q).Where P (Q) denotes the power set of Q.

3. NDFAs where introduced by ____________
a) Michael O Rabin & Dana Scott
b) Dan Brown
c) Sun micro system Labs
d) SAP Labs

Answer: a
Clarification: NFAs were introduced Dana Scott and Michael O. Rabin who also showed their equivalence to DFAs.

4. The regular languages are not closed under ___________
a) Concatenation
b) Union
c) Kleene star
d) Complement

Answer: d
Clarification: RE are closed under

 

  • Union (cf. picture)
  • Intersection
  • Concatenation
  • Negation
  • Kleene closure.

 

5. The Tuples for NDFA is ___________
a) ∑, Q, q0, F, δ
b) Q, q0, F, δ
c) Θ, Q, q0, F,δ
d) F, Q, Δ, q0, δ

Answer: a
Clarification: An NFA is represented formally by a 5-tuple, (Q, Σ, Δ, q0, F), of

 

  • a set of states Q
  • a set of input symbols Σ
  • a transition function Δ : Q × Σ → P(Q).
  • an initial state q0 ∈ Q
  • a final state F ⊆ Q.

250+ TOP MCQs on Context Free Grammar and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Context free Grammar”.

1. Assume the statements S1 and S2 given as:
S1: Given a context free grammar, there exists an algorithm for determining whether L (G) is infinite.
S2: There exists an algorithm to determine whether two context free grammars generate the same language.
Which of the following is true?
a) S1 is correct and S2 is not correct
b) Both S1 and S2 are correct
c) Both S1 and S2 are not correct
d) S1 is not correct and S2 is correct

Answer: a
Clarification: The proof of S1 can be seen in various book of theory of computation but s2 is a problem of category undecidable so a contradiction to this assumption can be easily obtained.

2. If P & R are regular and also given that if PQ=R, then?
a) Q has to be regular
b) Q cannot be regular
c) Q need not be regular
d) Q has to be a CFL

Answer: c
Clarification: If two regular languages when combined do not always produce a regular language.

3. Which of the following conversion is not possible (algorithmically)?
a) Regular grammar to CFG
b) NDFA to DFA
c) NDPDA to DPDA
d) NDTM to DTM

Answer: c
Clarification: Not every NDPDA has an equivalent deterministic PDA.

4. Consider the grammar given below E? E+E | E*E | E-E | E/E | E^E | (E) | id Assume that + and ^ have the same but least precedence, * and / have the next higher precedence but the same precedence and finally ^ has the highest precedence. Assume + and ^ associate to the left like * and / and that ^ associates to the right. Choose the correct for the ordered pairs (^,^), (-,-), (+,+), (*,*) in the operator precedence table constructed for the grammar.
a) All <
b) All >
c) < >, =
d) < > > >

Answer: d
Clarification: This relation is established of basis of the precedence of operators.

5. Recursively enumerable languages are not closed under ______________
a) Union
b) Intersection
c) Complementation
d) Concatenation

Answer: c
Clarification: Recursive languages are closed under the following operations.
The Kleene star L * of L
the concatenation L * o P of L and P
the union L U P
the intersection L ∩ P.

6. Grammar that produce more than one Parse tree for same sentence is ___________
a) Ambiguous
b) Unambiguous
c) Complementation
d) Concatenation Intersection

Answer: a
Clarification: An ambiguous grammar is one for which there is more than one parse tree for a single sentence.

7. Automaton accepting the regular expression of any number of a’ s is ___________
a) a*
b) ab*
c) (a/b)*
d) a*b*c

Answer: a
Clarification: It gives any number of a’s.

8. Grammars that can be translated to DFAs is ___________
a) Left linear grammar
b) Right linear grammar
c) Generic grammar
d) All of the mentioned

Answer: b
Clarification: Right linear grammar can be translated to the DFAs.

9. Which of the following language accepted by a Push down Automata?
a) Type0
b) Type1
c) Type2
d) Type3

Answer: c
Clarification: A known fact that type 2 grammar is accepted by PDA.

10. Given the following statements: (i) Recursive enumerable sets are closed under complementation. (ii) Recursive sets are closed under complements. Which is/are the correct statements?
a) I only
b) II only
c) Both I and II
d) Neither I nor II

Answer: b
Clarification: Recursive languages are closed under the following operations.
The Kleene star L * of L
The concatenation L * o P of L and P
The union L U P
The intersection L ∩ P.