250+ TOP MCQs on Applications – Parsers and Answers

Automata Theory Multiple Choice Questions on “Applications – Parsers”.

1. To derive a string using the production rules of a given grammar, we use:
a) Scanning
b) Parsing
c) Derivation
d) All of the mentioned

Answer: b
Clarification: Parsing is required to check the acceptability of a string. Further, comes the syntactical phase which is taken care by other phases of compiler.

2. Which of the following parser reaches the root symbol of the tree at last?
a) Top down parser
b) Bottom up parser
c) TOP down and Bottom up parser
d) None of the mentioned

Answer: b
Clarification: Bottom up parser starts from the bottom with the string and comes up to the start symbolusing a parse tree or a derivation tree.

3. Left corner parsing methof uses which of the following?
a) Top down parser
b) Bottom up parser
c) TOP down and Bottom up parser
d) None of the mentioned

Answer: c
Clarification: It is a hybrid method which works bottom up along the left edges of each subtree, and top down on the rest of the parse tree.

4. Which of the following parser performs top down parsing?
a) LALR parser
b) LL parser
c) Recursive Accent parser
d) None of the mentioned

Answer: b
Clarification: Bottom up parsing is done by shift reduce parsers like LALR parsers, Operator precedence parsers, simple precedence parsers, etc.

5. Which of the following is true for shift reduce parsers?
a) Scans and parses the input in one forward pass over the text, without any backup.
b) A shift command advances in the input stream by one symbol
c) LALR parser
d) All of the mentioned

Answer: d
Clarification: The mentioned are the correct and proper functions of a shift reduce parsers. The parsing methods are most commonly used for parsing programming languages, etc.

6. State true or false:
Statement: LALR parsers uses tables rather than mutually recursive functions.
a) true
b) false

Answer: b
Clarification: It is exactly the opposite case where LALR parsers uses mutually recursive functions instead of tables. It is a simplified version of canonical left to right parser.

7. LALR in LALR parser stands for:
a) Left aligned left right parser
b) Look ahead left to right parser
c) Language Argument left to right parser
d) None of the mentioned

Answer:
Clarification: LALR stands for Look ahead left to right parsers. It has more language recognition power than LR(0) parser.

8. Which of the following can be a LALR parser generator?
a) YACC
b) GNU Bison
c) YACC and GNU Bison
d) None of the mentioned

Answer: c
Clarification: YACC is a computer code for UNIX operating system which generates a LALR parser. On the other hand GNU Bison or Bison can generate LALR and GLR parsers.

9. Which of the following parsers do not relate to Bottom up parsing?
a) LL parser
b) Recursive descent parser
c) Earley parsers
d) All of the mentioned

Answer: d
Clarification: All the following mentioned are top down parsers and begin their operation from the starting symbol.

10. Which of the following is true for a predictive parser?
a) Recursive Descent parser
b) no backtracking
c) Recursive Descent parser and no backtracking
d) None of the mentioned

Answer: c
Clarification: Predictive parsing is possible only for the class of LL-grammars, which are the CFG for which there exists some positive integer k that allows a recursive descent parser to decide which production to use by examining only the next k tokens of input.

250+ TOP MCQs on Pumping Lemma for Context Free Language

Automata Theory Questions and Answers for Campus interviews on “Pumping Lemma for Context Free Language”.

1. Which of the following is called Bar-Hillel lemma?
a) Pumping lemma for regular language
b) Pumping lemma for context free languages
c) Pumping lemma for context sensitive languages
d) None of the mentioned

Answer: b
Clarification: In automata theory, the pumping lemma for context free languages, also kmown as the Bar-Hillel lemma, represents a property of all context free languages.

2. Which of the expressions correctly is an requirement of the pumping lemma for the context free languages?
a) uvnwxny
b) uvnwnxny
c) uv2nwx2ny
d) All of the mentioned

Answer: b
Clarification: Let L be a CFL. Then there is an integer n so that for any u that belong to language L satisfying |t| >=n, there are strings u, v, w, x, y and z satisfying
t=uvwxy
|vx|>0
|vwx|=0, uvnwxny ∈ L

3.Let L be a CFL. Then there is an integer n so that for any u that belong to language L satisfying
|t|>=n, there are strings u, v, w, x, y and z satisfying
t=uvwxy.
Let p be the number of variables in CNF form of the context free grammar. The value of n in terms of p :
a) 2p
b) 2p
c) 2p+1
d) p2

Answer: c
Clarification: This inequation has been derived from derivation tree for t which must have height at least p+2(It has more than 2p leaf nodes, and therefore its height is >p+1).

4. Which of the following gives a positive result to the pumping lemma restrictions and requirements?
a) {aibici|i>=0}
b) {0i1i|i>=0}
c) {ss|s∈{a,b}*}
d) None of the mentioned

Answer: b
Clarification: A positive result to the pumping lemma shows that the language is a CFL and ist contradiction or negative result shows that the given language is not a Context Free language.

5. Using pumping lemma, which of the following cannot be proved as ‘not a CFL’?
a) {aibici|i>=0}
b) {ss|s∈{a,b}*}
c) The set legal C programs
d) None of the mentioned

Answer: d
Clarification: There are few rules in C that are context dependent. For example, declaration of a variable before it can be used.

6. State true or false:
Statement: We cannot use Ogden’s lemma when pumping lemma fails.
a) true
b) false

Answer: b
Clarification: Although the pumping lemma provides some information about v and x that are pumped, it says little about the location of these substrings in the string t. It can be used whenever the pumping lemma fails. Example: {apbqcrds|p=0 or q=r=s}, etc.

7. Which of the following cannot be filled in the blank below?
Statement: There are CFLs L1 nad L2 so that ___________is not a CFL.
a) L1∩L2
b) L1′
c) L1*
d) None of the mentioned

Answer: c
Clarification: A set of context free language is closed under the following operations:
a) Union
b) Concatenation
c) Kleene

8. The pumping lemma is often used to prove that a language is:
a) Context free
b) Not context free
c) Regular
d) None of the mentioned

Answer: b
Clarification: The pumping lemma is often used to prove that a given language L is non-context-free, by showing that arbitrarily long strings s are in L that cannot be “pumped” without producing strings outside L.

9. What is the pumping length of string of length x?
a) x+1
b) x
c) x-1
d) x2

Answer: a
Clarification: There exists a property of all strings in the language that are of length p, where p is the constant-called the pumping length .For a finite language L, p is equal to the maximum string length in L plus 1.

10. Which of the following does not obey pumping lemma for context free languages ?
a) Finite languages
b) Context free languages
c) Unrestricted languages
d) None of the mentioned

Answer: c
Clarification: Finite languages (which are regular hence context free ) obey pumping lemma where as unrestricted languages like recursive languages do not obey pumping lemma for context free languages.

250+ TOP MCQs on Rice’s Theorem, Properties and PCP and Answers

Automata Theory Multiple Choice Questions on “Rice’s Theorem, Properties and PCP”.

1. According to the rice’s theorem, If P is a non trivial property, Lp is :
a) infinite
b) decidable
c) undecidable
d) none of the mentioned

Answer: c
Clarification: Rice’s theorem states that ‘Any non trivial property about the language recognized by a turing machine is undecidable’.

2. Fill in the blank with reference to Rice’s theorem.
For any non-trivial property of __________ no general or effective method can decide whether an algorithm computes it with that property.
a) partial functions
b) piecewise functions
c) both (a) and (b)
d) none of the mentioned

Answer: a
Clarification: A property of partial functions is called trivial if it holds for all partial computable functions or for none, and an effective decision method is called general if it decides correctly for every algorithm.

3. Which of the following is incorrect according to rice theorem?
Let S be a set of language hat is non trivial:
a) there exists a TM that recognizes the language in S
b) there exists a TM that recognizes the language not in S
c) both (a) and (b)
d) none of the mentioned

Answer: c
Clarification: According to rice theorem, it is undecidable to determine whether the language recognized by an arbitrary turing machine lies in S.

4. Which of the following set of computable functions are decidable?
a) The class of computable functions that are constant, and its complement
b) The class of indices for computable functions that are total
c) The class of indices for recursively enumerable sets that are cofinite
d) All of the mentioned

Answer: d
Clarification: According to Rice’s theorem, if there exists atleast one computable function in a particular class C of computable functions and another computable function not in C then the problem deciding whether a particular program computes a function in C is undecidable.

5. Which of the following statements are undecidable?
For a given Turing Machine M,
a) does M halt on an empty input tape
b) does M halt for anly inputs at all?
c) is L(M) regular? Context free? Turing decidable?
d) all of the mentioned

Answer: d
Clarification: All of the following mentioned are immediate results of Rice’s theorem and thus, undecidable.

6. Post Correspondence problem is
a) decidable decision problem
b) undecidable decision problem
c) not a decision problem
d) none of the mentioned

Answer: b
Clarification: Post Correspondence problem is an undecidable decision problem that was introduced by Emil Post in 1946. Being simpler than halting problem, it can be used in proofs of undecidability.

7. State true or false:
Statement: The difference between PCP and MPCP is that in MPCP, a solution is required to start with the first string on each list.
a) true
b) false

Answer: a
Clarification: The MPCP is : Given lists A and B of K strings ,say A = w1 ,w2, …wk and B= x1, x2,…..xk does there exists a sequence of integers i1,i2,…ir such that w1wi1wi2…..wir = x1xi1xi2…xir?

8. PCP stands for?
a) Post Correspondence Problem
b) Post Corresponding Problem
c) Pre Correspondence problem
d) None of the mentioned

Answer: a
Clarification: PCP or Post Correspondence problem is an undecidable decision problem.

9. Can a Modified PCP problem be reduced to PCP?
a) yes
b) no

Answer: a
Clarification: Yes, it can be. There exists a theorem and as well as its proof which supports the assertion.

10. Consider three decision problem A, B, C. A is decidable and B is not. Which of the following is a correct option?
a) C is undecidable if C is reducible to B
b) C is undecidable if B is reducible to C
c) C is decidable if A is reducible to C
d) C is decidable if C is reducible to B’s complement.

Answer: b
Clarification: As B is undecidable and it can be reduced to C, C is also an undecidable problem.

250+ TOP MCQs on The Language of NFA and Answers

Automata Theory Multiple Choice Questions on “The Language of NFA”.

1. Subset Construction method refers to:
a) Conversion of NFA to DFA
b) DFA minimization
c) Eliminating Null references
d) ε-NFA to NFA

Answer: a
Clarification: The conversion of a non-deterministic automata into a deterministic one is a process we call subset construction or power set construction.

2. Given Language:
Ln= {xϵ {0,1} * | |x|≥n, nth symbol from the right in x is 1}
How many state are required to execute L3 using NFA?
a) 16
b) 15
c) 8
d) 7

Answer: b
Clarification: The finite automaton for the given language is made and thus, the answer can be obtained.

3. Which of the following is a regular language?
a) String whose length is a sequence of prime numbers
b) String with substring wwr in between
c) Palindrome string
d) String with even number of Zero’s

Answer: d
Clarification: DFSM’s for the first three option is not possible; hence they aren’t regular.

4. Which of the following recognizes the same formal language as of DFA and NFA?
a) Power set Construction
b) Subset Construction
c) Robin-Scott Construction
d) All of the mentioned

Answer: d
Clarification: All the three option refers to same technique if distinguishing similar constructions for different type of automata.

5. If L is a regular language, Lc and Lr both will be:
a) Accepted by NFA
b) Rejected by NFA
c) One of them will be accepted
d) Cannot be said

Answer: a
Clarification: If L is a regular Language, Lc and Lr both are regular even.

6. In NFA, this very state is like dead-end non final state:
a) ACCEPT
b) REJECT
c) DISTINCT
d) START

Answer: b
Clarification: REJECT state will be like a halting state which rejects a particular invalid input.

7. We can represent one language in more one FSMs, true or false?
a) TRUE
b) FALSE
c) May be true
d) Cannot be said

Answer: a
Clarification: We can represent one language in more one FSMs, example for a same language we have a DFA and an equivalent NFA.

8. The production of form non-terminal -> ε is called:
a) Sigma Production
b) Null Production
c) Epsilon Production
d) All of the mentioned

Answer: b
Clarification: The production of form non-terminal ->ε is call null production.

250+ TOP MCQs on Regular Expression in UNIX and Answers

Automata Theory Multiple Choice Questions on “Regular Expression in UNIX”.

1. Which among the following is not a UNIX command for regular expressions?
a) ed
b) sed
c) vi
d) none of the mentioned

Answer: d
Clarification: Regular expressions are used by different commands in Unix like ed, sed, grep, awk, vi, etc. Sed stands for stream editor which is exclusively used for executing scripts.

2. What is the significance of $ used in regular expression in UNIX?
a) Matches the beginning of the line
b) Matches the end of lines
c) Matches any single character
d) None of the mentioned

Answer: b
Clarification: Regular expression provides more flexibility while matching string patterns. Special characters like ^, $, *, . are very useful.

3. Generate the regular expression to match blank lines
a) / */
b) /bl
c) /^?/
d) /^$/

Answer: d
Clarification: There are few expressions which provide the utility of matching metacharacters including /^$/ for blank lines, / */ for matching one or more spaces, /^.*$/ for matching an entire line whatever it is.

4. For the given syntax of sed, which among the following is not a correct option?
General syntax of sed: /pattern/action
a) / are used as delimiters
b) pattern refers to a regular expression
c) pattern refers to the string to be matched
d) action refers to the command

Answer: c
Clarification: In the general syntax of sed, pattern is the regular expression and action refers to the command given (p: prints the line, d: deletes the line, etc).

5. What does grep do in UNIX?
a) It is an editor in UNIX
b) It searches for text patterns
c) Both (a) and (b)
d) None of the mentioned

Answer: b
Clarification: The grep is a standard UNIX utility program that searches through a set of files in search of a text pattern,specified through a regular expression.

6. State true or false:
Statement: A regular expression is a sequence of characters that represent a pattern.
a) true
b) false

Answer: a
Clarification: Such a generated pattern could be a fixed word or describe something like more general.

7. Which of the following options support the given statement?
Statement: A regular expression could be a fixed word or describe something like more general.
a) This flexibility makes Regular expression invaluable.
b) This flexibility makes the Regular expression unvaluable.
c) Both (a) and (b)
d) None of the mentioned

Answer: a
Clarification: Regular expressions are very much invaluable tools; they can be used to find a particular segment of line in a file and instruct to take certain actions.

8. What does the following segment of code does?
grep -i man heroes.txt
a) manually opens a file called heroes.txt
b) manages heroes.txt
c) search for “man” in the file “heroes.txt”
d) none of the mentioned

Answer: c
Clarification: grep is a command which finds the pattern in a particular text segment.Here, it scans each line in heroes.txt and looks for an m followed by a and then followed by n.

9. What does “X?” do regular expression operator?
a) Matches zero or more capital X’s.
b) Matches no or one occurence of the capital letter X.
c) Matches one or more capital X’s.
d) All of the mentioned

Answer: b
Clarification: There are many other common regular expression operators like $, ^, etc. Which have their own respective purposes.

10. Which of the following does not support regular expressions?
a) sed
b) awk
c) emacs
d) none of the mentioned

Answer: d
Clarification: There are many UNIX tools including vi, Emacs, sed, awk and modern programming languages which support regular expressions.

250+ TOP MCQs on YACC Parser Generator and Answers

Automata Theory Multiple Choice Questions on “YACC Parser Generator”.

1. YACC is a computer program for ______ operation system.
a) Windows
b) DOS
c) Unix
d) openSUSE

Answer: c
Clarification: YACC technique is a computer code for the Unix operating system. It is a LALR parser generator, generating a parser, the part of a compiler that tries to make syntactic sense of the source code.

2. YACC is an acronym for:
a) Yes Another Compile Compiler
b) Yet Another Compile Compiler
c) Yet Another Compiler Compiler
d) Yes Another Compiler Compiler

Answer: c
Clarification: YACC stands for ‘Yet another compiler compiler’ and it was developed by Stephen Johnson in B programming language later translated to C.

3. The YACC takes C code as input and outputs_________
a) Top down parsers
b) Bottom up parsers
c) Machine code
d) None of the mentioned

Answer: b
Clarification: The YACC takes C code as input and produces shift reduce parsers in C,also known as Bottom up parsers which execute C snippets with the associated rule.

4. The _______ table is created by YACC.
a) LALR parsing
b) LL parsing
c) GLR parsing
d) None of the mentioned

Answer: a
Clarification: LALR parser generator is software tool that reads a BNF grammar and creates a LALR parser which is capable of parsing files written in programming language identified by BNF grammar.

5. The original YACC as written in __________ language
a) R programming language
b) C programming language
c) B programming language
d) None of the mentioned

Answer: c
Clarification: Stephen Johnson wrote this parser generator in B programming language which was further modified and written in C, JAVA, Python, etc.

6. Which of the following is false for B programming language?
a) Typeless
b) Influenced by PL/I
c) Designed by Dennis Ritchie
d) None of the mentioned

Answer: d
Clarification: B was programming language designed by Dennis Ritchie and Ken Thompson for recursive, non numeric, system and language softwares. It was a typeless language, everything is a word.

7. Which of the following is false for BNF?
a) BNF means Backus Naur Form
b) It is a normal form used in Data base normalization
c) It is a notation technique for context free grammar
d) None of the mentioned

Answer: b
Clarification: The normal form used in Data base normalization is BCNF i.e. Boyce Codd normal form and NOT Backus Naur Form.

8. State true or false:
Statement: BNF is a metasyntax used to express CFG
a) True
b) False

Answer: a
Clarification: BNF is a metasyntax used to express context free grammar, moreover a formal way to express the language.

9. Which of the following are not used to express CFG?
a) BNF
b) EBNF, ABNF
c) Van Wijngaarden form
d) None of the mentioned

Answer: d
Clarification: W grammar or van Wijngaarden form is used to define potentially infinite context free grammars in a finite number of rules. It is an example of larger class of affix grammars. This technique was used to define the P/L Algol 68.

10. Which of the following version of Unix came up with YACC first?
a) V3
b) V5
c) CB UNIX
d) Unix-RT

Answer: a
Clarification: Yacc appeared in version 3 of unix, though full description was published by 1975.