250+ TOP MCQs on LR Parser and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “LR Parser”.

1. Which of these is also known as look-head LR parser?
a) SLR
b) LR
c) LLR
d) None of the mentioned

Answer: c
Clarification: LLR is the look ahead parser.

2. What is the similarity between LR, LALR and SLR?
a) Use same algorithm, but different parsing table
b) Same parsing table, but different algorithm
c) Their Parsing tables and algorithm are similar but uses top down approach
d) Both Parsing tables and algorithm are different

Answer: a
Clarification: The common grounds of these 3 parser is the algorithm but parsing table is different.

3. An LR-parser can detect a syntactic error as soon as __________
a) The parsing starts
b) It is possible to do so a left-to-right scan of the input
c) It is possible to do so a right-to-left scan of the input
d) Parsing ends

Answer: b
Clarification: Error is found when it the input string is scanned.

4. Which of these is true about LR parsing?
a) Is most general non-backtracking shift-reduce parsing
b) It is still efficient
c) Is most general non-backtracking shift-reduce parsing & It is still efficient
d) None of the mentioned

Answer: c
Clarification: LR parsers are a type of bottom-up parsers that efficiently handle deterministic context-free languages in guaranteed linear time.

5. Which of the following is incorrect for the actions of A LR-Parser I) shift s ii) reduce A->ß iii) Accept iv) reject?
a) Only I)
b) I) and ii)
c) I), ii) and iii)
d) I), ii) , iii) and iv)

Answer: c
Clarification: Only reject out of the following is a correct LR parser action.

6. If a state does not know whether it will make a shift operation or reduction for a terminal is called _________
a) Shift/reduce conflict
b) Reduce /shift conflict
c) Shift conflict
d) Reduce conflict

Answer: a
Clarification: As the name suggests that the conflict is between shift and reduce hence it is called shift reduce conflict.

7. When there is a reduce/reduce conflict?
a) If a state does not know whether it will make a shift operation using the production rule i or j for a terminal
b) If a state does not know whether it will make a shift or reduction operation using the production rule i or j for a terminal
c) If a state does not know whether it will make a reduction operation using the production rule i or j for a terminal
d) None of the mentioned

Answer: c
Clarification: It occurs when If a state does not know whether it will make a reduction operation using the production rule i or j for a terminal.

8. When ß (in the LR(1) item A -> ß.a,a) is not empty, the look-head _________
a) Will be affecting
b) Does not have any affect
c) Shift will take place
d) Reduction will take place

Answer: b
Clarification: There is no terminal before the non terminal beta.

9. When ß is empty (A -> ß.,a), the reduction by A-> a is done by _________
a) If next symbol is a terminal
b) Only If the next input symbol is a
c) Only If the next input symbol is A
d) Only if the next input symbol is a

Answer: d
Clarification: The next token is considered in this case it’s a.

10. The construction of the canonical collection of the sets of LR (1) items are similar to the construction of the canonical collection of the sets of LR (0) items. Which is an exception?
a) Closure and goto operations work a little bit different
b) Closure and goto operations work similarly
c) Closure and additive operations work a little bit different
d) Closure and associatively operations work a little bit different

Answer: a
Clarification: Closure and goto do work differently in case of LR (0) and LR (1).

250+ TOP MCQs on Implementation of Increment and Decrement Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Implementation of Increment and Decrement – 1”.
1. What value does the variable b have after ALL of the code executes?

int a;
int b;
a=1;
b=a++;

a) 1
b) 2
c) 3
d) unknown/undefined

Answer: a
Clarification: b will be one because when value of ais 1 it is stored.

2. What value does the variable a have after ALL of the code above executes?

int a;
int b;
a=1;
b=a++;

a) 1
b) 2
c) 3
d) unknown/undefined

Answer: b
Clarification: a=2 cause it has been incremented.

3. What value does the variable z have after ALL of the code above executes?

int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;

a) 9
b) 12
c) 16
d) 20

Answer: c
Clarification: z=4* 4
Hence the answer will be 16.

4. What value does the variable x have after ALL of the code above executes?

int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;

a) 2
b) 3
c) 4
d) unknown/undefined

Answer: c
Clarification: Finally the value of x is 4.

5. What value does the variable y have after ALL of the code above executes?

int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;

a) 4
b) 5
c) 6
d) unknown/undefined

Answer: b
Clarification: The value of y is increased by 1 and becomes 5.

6. What will be the output of the following program?

#include
int main()
{
    int i = 10;
    printf("%d", ++(-i));
    return 0;
}

a) 11
b) 10
c) -9
d) None of the mentioned

Answer: d
Clarification: The expression ++(-i) is not valid but –(++i) is valid.

7. What will be output of the following C code?

#‎include‬ 
int main()
{
    int x=4, y, z;
    y = --x;
    z = x--;
    printf("%d, %d, %dn", x, y, z);
    return 0;
}

a) 4,3,3
b) 3,3,3
c) 2,3,3
d) 4,4,3

Answer: c
Clarification: y = 3 and z= 3 but
x has decremented and become 2.

8. What will be output of the following C code?

#include 
main()
{
    int a=1, b=3;
    b= a++ + a++ + a++ + a++ + a++;
    printf("a=%d n b=%d",a,b); 
}

a) a = 6, b = 15
b) a = 1, b = 3
c) a = 1, b = 15
d) a = 2, b = 4

Answer: a
Clarification: B=1+2+3+4+5
B=15
But finally a=6.

9. What will be output of the following C code?

#include 
main()
{
    int a=9, b=9;
    a=b++;
    b=a++;
    b=++b; 
    printf("%d %d",a,b);
}

a) 9,9
b) 10,10
c) 9,10
d) 10,9

Answer: b
Clarification: A=9
B=9
B=10

10. What will be output of the following C code?

#include 
main()
{  
     int a,b;
     b = 10;
     a = ++b + ++b;
     printf("%d%d",a,b);
}

a) 24,12
b) 23,12
c) 23,10
d) 24,10

Answer: b
Clarification: A = 11+12
So a=23
B=12.

250+ TOP MCQs on Finite Automata and Answers Quiz Exam

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

1. A language L from a grammar G = { VN, Σ, P, S} is?
a) Set of symbols over VN
b) Set of symbols over Σ
c) Set of symbols over P
d) Set of symbols over S

Answer: b
Clarification: The definition of the grammar is set of symbols over Σ.

2. What is the transitional function of a DFA?
a) Q X Σ→Q
b) Q X Σ→2Q
c) Q X Σ→2n
d) Q X Σ→Qn

Answer: a
Clarification: Q is the finite set and let be a finite set of symbols so Q X Σ fives no of states.

3. What is the transitional function of an NFA?
a) Q X Σ→Q
b) Q X Σ→2Q
c) Q X Σ→2n
d) Q X Σ→Qn

Answer: b
Clarification: Let Q be a finite set and let be a finite set of symbols. Also let be a function from Q to 2Q. All the elements of Q a state, the transition function, q0 the initial state and A the set of accepting states.
Then a nondeterministic finite automaton is a 5-tuple < Q, , q0, , A >.

4. Maximum number of states of a DFA converted from an NFA with nstates is?
a) n
b) n2
c) 2n
d) None of the mentioned

Answer: c
Clarification: Take the NFA with states {qo,q1}, alphabet Σ={a}, initial state q0, transitions δ(q0,a)=q0, δ(q0,a)=q1 and final state q1. It generates the same language as the DFA with the same set of states and alphabet, but transitions δ(q0,a)=q1 and δ(q1,a)=q1.

5. What are the basic limitations of finite state machine?
a) It cannot remember arbitrarily large amount of information
b) In cannot remember state transitions
c) In cannot remember grammar for a language
d) It cannot remember language generated from a grammar

Answer: b
Clarification: Because it does to store its previous state of the transition.

6. The string WWR is not recognized by any FSM because _____________
a) An FSM cannot remember arbitrarily large amount of information
b) An FSM cannot fix the midpoint
c) An FSM cannot match W with WR
d) An FSM cannot remember first and last inputs

Answer: b
Clarification: Palindromes cannot be recognized by FSM.

7. A finite automata recognizes ____________
a) Any Language
b) Context Sensitive Language
c) Context Free Language
d) Regular Language

Answer: d
Clarification: All regular languages are implemented by finite automata.

250+ TOP MCQs on Syntax Analyser and Answers

Compilers Multiple Choice Questions on “Syntax Analyser”.

1. Which phase of the compiler is Syntax Analysis?
a) First
b) Second
c) Third
d) None of the mentioned

Answer: b
Clarification: It is Second Phase Of Compiler after Lexical Analyzer.

2. Syntax Analyser is also known as ___________
a) Hierarchical Analysis
b) Hierarchical Parsing
c) None of the mentioned
d) Hierarchical Analysis & Parsing

Answer: d
Clarification: It is also called as Hierarchical Analysis or Parsing.

3. Syntax Analyser takes Groups Tokens of source Program into Grammatical Production.
a) True
b) False

Answer: a
Clarification: It Groups Tokens of source Program into Grammatical Production.

4. From where it takes its input from?
a) Lexical analyser
b) Syntactic Analyser
c) Semantic Analyser
d) None of the mentioned

Answer: a
Clarification: A syntax analyzer or parser takes the input from a lexical analyzer in the form of token streams.

5. Parsers are expected to parse the whole code.
a) True
b) False

Answer: a
Clarification: Parsers are expected to parse the whole code even if some errors exist in the program.

6. A grammar for a programming language is a formal description of _______________
a) Syntax
b) Semantics
c) Structure
d) Library

Answer: c
Clarification: The grammar clearly indicates which type of structure does a program has.

7. Which of these is not true about the Symbol Table?
a) All the labels of the instructions are symbols
b) Table has entry for symbol name address value
c) Perform the processing of the assembler directives
d) Created during pass 1

Answer: c
Clarification: The Symbol table does not ever perform the processing of the assembler derivative.

8. Which of these features of assembler are Machine-Dependent?
a) Instruction formats
b) Addressing modes
c) Program relocation
d) All of the mentioned

Answer: d
Clarification: All of these options are features of assembler which are machine dependent.

9. A compiler can check?
a) Logical Error
b) Syntax Error
c) Both Logical and Syntax Error
d) Not Logical and Syntax Error

Answer: b
Clarification: No compiler can ever check logical errors.

10. The fourth Generation computer was made up of ______________
a) Transistor
b) Vacuum tubes
c) Chips
d) Microprocessor chips

Answer: d
Clarification: It is the only way to increase its throughput.

250+ TOP MCQs on LR Parser and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “LR Parser”.

1. What is terminal table?
a) Contains all constants in the program
b) Is a permanent table of decision rules in the form of patterns for matching with the uniform symbol table to discover syntactic structure
c) Consist of a full or partial list of the token is as they appear in the program created by lexical analysis and used for syntax analysis and interpretation
d) Is a permanent table which lists all keywords and special symbols of the language in symbolic form

Answer: d
Clarification: A permanent database that has entry for each terminal symbols such as arithmetic operators, keywords, punctuation characters such as ‘;’, ‘,’etc Fields: Name of the symbol.

2. Advantage of incorporating the macro-processor into pass 1 is that _________
a) Many functions have to be implemented twice
b) Functions are combined not necessarily creating intermediate files as output from the macro-processor and input to the assembler
c) More flexibility is provided to the programmer in that he may use all the features of the assembler in conjunction with macros
d) All of the mentioned

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

3. Which of the following is a phase of a compilation process?
a) Lexical Analysis
b) Code Generation
c) Lexical Analysis & Code Generation
d) None of the mentioned

Answer: c
Clarification: Lexical analysis and code generation is a phase of compilation process.

4. System program such as compiler are designed so that they are _________
a) Re-enterable
b) Non reusable
c) Serially usable
d) None of the mentioned

Answer: a
Clarification: Re-enterable is the keyword for compiler being designed.

5. A series of statements explaining how the data is to be processed is called _________
a) Assembly
b) Machine
c) COBOL
d) Program

Answer: d
Clarification: A program is a sequence of instructions, written to perform a task by computer. It requires programs to function, typically executing the program’s instructions in a central processor.

6. A loader is a program that _________
a) Program that places functions into memory and prepares them for execution
b) Program that automates the translation of assembly language into machine language
c) Program accepting another program written in a high level language and produces as object program
d) None of the mentioned

Answer: a
Clarification: A loader is the part of an operating system that is responsible for loading programs and libraries. It is important in the process of placing the programs into memory and executing them.

7. A system program that setup an executable program in main memory ready for execution is?
a) Assembler
b) Linker
c) Loader
d) Load and go

Answer: c
Clarification: A loader is the part of an operating system that is responsible for loading programs and libraries. It is one of the essential stages in the process of starting a program, as it places programs into memory and prepares them for execution.

8. Which of the following system program forgoes the production of object code to generate absolute machine code and load it into the physical main storage location from which it will be executed immediately upon completion of the assembly?
a) Two pass assembler
b) Load and go assembler
c) Macro processor
d) Linker

Answer: b
Clarification: A load and go assembler generates absolute machine code and loads it to physical memory.

9. Uniform symbol table _________
a) Has all constants in the program
b) Permanent table of rules in the form of patterns for matching with the uniform symbol table to discover syntactic structure
c) Consists of full or partial list of the tokens as they appear in the program created by Lexical analysis and used for syntax analysis and interpretation
d) A permanent table which has all key words and special symbols of the language in symbolic form

Answer: c
Clarification: Each pass scans the program, the first pass generates the symbol table and the second pass generates the machine code.

10. Assembler is a program that _________
a) Puts programs into memory and executes them
b) Translates the assembly language into machine language
c) Writes in high level language and produces an object program
d) None of the mentioned

Answer: b
Clarification: An assembler is a program that takes basic computer instructions and converts them into a pattern of bits that the computer’s processor can use to perform its basic operations.

250+ TOP MCQs on Implementation of Increment and Decrement

Compilers Questions and Answers for Aptitude test on “Implementation of Increment and Decrement”.

1. In C programming language, which of the following type of operators have the highest precedence?
a) Relational Operators
b) Equality Operators
c) Logical Operators
d) Arithmetic Operators

Answer: d
Clarification: No other operator has higher precedence than arithmetic operator.

2. Which of the following operators has the highest precedence?
a) Unary +
b) *
c) >=
d) ==

Answer: a
Clarification: Unary operators have max precedence in over all other arithmetic operators.

3. If i=1 j=2,k=3, then what is the value of the following expression?

a) 6
b) 5
c) 1
d) 0

Answer: c
Clarification: !((2+3)>(1+5))
!(5>6)
Since the condition is false hence !(0)
And complement of 0 is 1.

4. The expression 5 – 2 – 3 * 5 – 2 will evaluate to 18, if – is left associative and _____________
a) * has precedence over *
b) * has precedence over –
c) – has precedence over *
d) – has precedence over –

Answer: c
Clarification: if – has precedence over* and if it associates from the right.

5. Coercion _____________
a) Takes place over an assignment operator
b) Operator has operands of various types
c) None of the mentioned
d) Takes place over an assignment operator & Operator has operands of various types

Answer: d
Clarification: Conversion between compatible types.

6. Choose the correct statement.
a) Expressions evaluated at compile time
b) String constants concatenated at compile time
c) None of the mentioned
d) Both of the mentioned

Answer: d
Clarification: The statements are true.

7. Which of the following operators takes only integer operands?
a) +
b) *
c) /
d) %

Answer: d
Clarification: Two integers are taken to be input.

8. Pick the operators that associate from the left.
a) +
b) ,
c) <
d) All of the mentioned

Answer: d
Clarification: They are left associative.

9. Pick the operators that associate from the right.
a) ?:
b) +=
c) =
d) All of the mentioned

Answer: d
Clarification: They are right associative.

10. Pick the operators that associate from left to right.
a) &&
b) ?:
c) ,
d) All of the mentioned

Answer: d
Clarification: They left to right associative.