Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

COMPILER MCQS

Compiler MCQs help learners strengthen their understanding of syntax, semantics, and code optimization techniques. These questions are designed for students pursuing computer science and preparing for university or job-related assessments.

Compiler MCQs

Why Choose Us

Structured Coverage: Includes every compiler phase — from lexical analysis to optimization.
Concept Clarity: Focuses on both theoretical and practical aspects.
Exam-Ready Format: Ideal for university and IT job exams.
Updated Content: Regularly refreshed to match modern compiler design techniques.
Quick Revision: Compact format for instant concept recall.

FAQs

Q1. What topics are covered in these MCQs?
Lexical analysis, parsing, intermediate code generation, and optimization.

Q2. Are these questions suitable for CS exams?
Yes, they are perfect for BSCS, MCS, and related entrance or job tests.

Q3. Are answers included?
Yes, every MCQ comes with a clear answer for self-evaluation.

Q4. Is this useful for competitive exams?
Yes, particularly for NTS, FPSC, and technical recruitment tests.

Q5. How often is content updated?
It’s updated quarterly to reflect new compiler concepts.

Conclusion

Compiler MCQs enhance your grasp on code translation, optimization, and parsing. Practice regularly to master these core concepts and boost your performance in technical exams.
Typingvilla

Lexical analysis is performed by:ScannerCode GeneratorAssemblerB) ScannerScanner breaks source code into tokens.
Which phase checks syntax errors?Syntax AnalysisSemantic AnalysisCode GenerationB) Syntax AnalysisSyntax analysis uses parsing to check grammar of code.
Intermediate code generation helps in:Syntax checkingTokenizationError reportingA) Machine independenceIntermediate code makes it easier to target multiple architectures.
Which parser is used in compilers for parsing expressions?Shift-ReduceOperator PrecedenceAll of the aboveD) All of the aboveCompilers can use different parsing techniques based on grammar.
Symbol table is used to store:Identifiers and their attributesOpcodesSource codeB) Identifiers and their attributesSymbol table keeps track of variables, functions, and their info.
Which of the following is the first phase of a compiler?Lexical AnalysisSyntax AnalysisSemantic AnalysisB) Lexical AnalysisLexical analysis scans source code and converts it into tokens.
Intermediate code generation is done to:Improve code readabilityMake compiler retargetable for different machinesPerform debuggingC) Make compiler retargetable for different machinesIntermediate code is platform-independent and simplifies code generation for multiple architectures.
A symbol table in a compiler stores:Information about variables, functions, objectsAssembly codeData flow graphB) Information about variables, functions, objectsSymbol table keeps identifiers and their attributes for semantic analysis and code generation.
Which parsing method uses a stack and works bottom-up?LR ParsingRecursive DescentTop-Down ParsingB) LR ParsingLR parsing is a bottom-up method that uses a stack and shift-reduce technique.
Peephole optimization is applied on:Intermediate representationTarget assembly codeSyntax treeC) Target assembly codePeephole optimization improves machine code by replacing inefficient instruction sequences.
Syntax tree is generated during:Semantic AnalysisSyntax AnalysisCode OptimizationC) Syntax AnalysisSyntax analysis (parsing) converts tokens into a parse tree representing grammatical structure.
Which phase detects type mismatch errors?Lexical AnalysisSemantic AnalysisOptimizationC) Semantic AnalysisSemantic analysis ensures type correctness and logical consistency.
A compiler that produces machine-independent code is called:Native CompilerOne-Pass CompilerBootstrapping CompilerA) Cross CompilerCross compilers generate code for a platform different from the host machine.
Which of these is NOT a compiler optimization technique?Dead Code EliminationStrength ReductionTokenizationD) TokenizationTokenization is a lexical analysis step, not an optimization technique.
Parsing table is used in:ParsingCode GenerationSymbol Table ManagementB) ParsingParsing table guides the parser to build syntax trees based on grammar rules.
Lexical analyzer outputs:TokensIntermediate CodeMachine CodeB) TokensLexical analysis breaks source code into tokens.
Intermediate code generation is done to:Improve portabilityDirectly produce machine codeSpeed up parsingB) Improve portabilityIntermediate code allows retargeting to multiple machine architectures.
Peephole optimization focuses on:Small set of instructionsParsing tableSyntax treeB) Small set of instructionsPeephole optimization improves short instruction sequences.
YACC is used for:Lexical AnalysisParsingSymbol Table ManagementC) ParsingYACC (Yet Another Compiler Compiler) generates parsers from grammar rules.
Which table stores variable information during compilation?Symbol TableLookup TableHash TableB) Symbol TableSymbol table keeps track of variables, types, and scopes.
Peephole optimization is performed in:Intermediate Code OptimizationSemantic AnalysisParsingB) Intermediate Code OptimizationPeephole optimization improves code by looking at small instruction sequences.
Left recursion is eliminated in:Code GenerationLexical AnalysisSymbol Table ManagementA) ParsingLeft recursion must be removed for top-down parsers to work.
Which parser uses lookahead symbols?LR(0)SLRCanonical LRA) LL(1)LL(1) parser uses one-token lookahead for decision making.
Semantic Analysis checks:Meaning of StatementsTokenizationCode ExecutionB) Meaning of StatementsSemantic analysis validates type compatibility, declarations, etc.
Backpatching is used in:Intermediate Code GenerationParsingLexical AnalysisB) Intermediate Code GenerationBackpatching fills forward jumps once target addresses are known.
exical analysis converts source code into:Parse Trees Intermediate Code Machine CodeA) Tokens Lexical analyzer breaks source into tokens for parser.
Which grammar removes ambiguity?Context-Sensitive GrammarRegular GrammarUnambiguous GrammarD) Unambiguous GrammarAmbiguity-free grammar ensures unique parse trees.
Intermediate code is generated to:Achieve machine independenceReduce errorsDirectly execute codeB) Achieve machine independenceIntermediate code provides portability before final code generation.
Which parsing is also called shift-reduce parsing?Bottom-Up ParsingLL ParsingPredictive ParsingB) Bottom-Up ParsingBottom-up parsers shift input symbols and reduce productions.
A symbol table stores:Variable names and attributesIntermediate codeError messagesB) Variable names and attributesSymbol table records identifiers with their type and scope.
The first phase of a compiler is:Lexical analysisSemantic analysisCode generationB) Lexical analysisLexical analysis scans input and produces tokens.
Intermediate code is generated to:Achieve portabilitySkip semantic checksIncrease errorsB) Achieve portabilityIntermediate code makes optimization and machine translation easier.
Which parser uses backtracking?LRRecursive descent Operator precedenceC) Recursive descentRecursive descent parsing often requires backtracking.
Peephole optimization is a type of:Machine-dependent optimizationCode parsingError correctionB) Machine-dependent optimizationPeephole optimization looks at small code patterns for replacement.
Tokens are recognized in which phase?ParsingOptimizationLinkingA) Lexical AnalysisLexical analysis divides source code into tokens.
Which parsing method uses backtracking?Recursive DescentLROperator PrecedenceB) Recursive DescentRecursive descent parsing may involve backtracking.
Which optimization reduces redundant calculations? Common subexpression eliminationLoop unrollingCode motionB) Common subexpression eliminationIt avoids repeated evaluation of the same expression.
Which parser is used in YACC?LRRecursive descentOperator precedenceB) LRYACC uses LR parsing.
Which phase checks type errors?Lexical AnalysisSemantic AnalysisCode OptimizationC) Semantic AnalysisSemantic analysis ensures type compatibility.
DAG in optimization stands for:Data Allocation GraphDirect Access GroupDynamic Allocation GraphA) Directed Acyclic GraphDAG helps in eliminating redundant expressions.
Lexical analysis produces:Syntax treeIntermediate codeMachine codeA) TokensLexical analyzer converts characters into tokens.
Operator precedence parsing avoids:Left recursionShift-reduce conflictsLeft factoringB) Left recursionPrevents infinite recursion in parsing.
Intermediate code is generated to:Provide portabilityReduce compile timeRemove redundancyB) Provide portabilityMakes code adaptable across platforms.
Symbol table stores:Variable names and attributesTokens onlyIntermediate codeB) Variable names and attributesSymbol tables map identifiers to details.
Left recursion in grammar causes:Shift-reduce conflictAmbiguityDeadlockA) Infinite recursion in top-down parserTop-down parsers cannot handle left recursion.
Lexical analysis converts source code into:TokensIntermediate codeMachine codeB) TokensLexer breaks code into token streams.
Which parser uses lookahead symbols?LL parserOperator precedence parserAll of the aboveD) All of the aboveParsers often require lookahead for decisions.
Intermediate code is generated to:Make compiler portableReduce memoryOptimize cacheB) Make compiler portableIntermediate code allows retargeting to many machines.
Peephole optimization is a type of:Local optimizationSyntax analysisSemantic analysisB) Local optimizationIt replaces inefficient code patterns.
Which phase ensures variables are declared before use?Syntax analysisSemantic analysisOptimizationC) Semantic analysisSemantic checks enforce correctness rules.
Which phase of compiler checks syntax errors?Syntax analysisSemantic analysisCode generationB) Syntax analysisSyntax analyzer ensures grammar correctness.
Intermediate code is generated for:DebuggingLinkingOptimization onlyA) PortabilityIntermediate code allows easier retargeting.
Lexical analysis outputs:Parse treeMachine codeIntermediate codeA) TokensLexical analysis breaks input into tokens.
Peephole optimization is done at:Intermediate codeAssembly/machine codeSource codeC) Assembly/machine codePeephole optimization improves small sections of code.
Which parsing method is used in YACC?Recursive descentOperator precedenceNoneD) NoneYACC uses LR parsing technique.
A symbol table is used for:Identifier managementMachine code generationTokenizationB) Identifier managementSymbol tables store variable and function information.
Semantic analysis checks:Meaning of statementsToken streamCode optimizationB) Meaning of statementsSemantic analysis verifies type and consistency.
Which optimization technique eliminates common subexpressions?Dead code eliminationCommon subexpression eliminationLoop unrollingC) Common subexpression eliminationIt avoids redundant computations.
Bootstrapping a compiler means:Compiler compiling itselfUsing another compilerWriting in machine codeB) Compiler compiling itselfBootstrapping allows self-compilation for portability.
The output of lexical analysis is:Syntax treeMachine codeBytecodeA) TokensLexical analyzer breaks input into tokens.
Left recursion in grammar affects:Lexical analysisSemantic analysisCode optimizationA) ParsingLeft recursion leads to infinite recursion in top-down parsers.
Intermediate code generation produces:Target codeAbstract representationTokensC) Abstract representationIntermediate code is machine-independent.
Which optimization eliminates common sub-expressions?Dead code eliminationConstant foldingCommon subexpression eliminationD) Common subexpression eliminationIt avoids recomputing identical expressions.
Which phase of the compiler is responsible for lexical analysis?ScannerOptimizerCode GeneratorB) ScannerThe scanner (lexical analyzer) converts source code into tokens for the parser.
What is the main purpose of an intermediate code in compilation?To make code generation easierTo execute code directlyTo detect runtime errorsB) To make code generation easierIntermediate code provides a platform-independent representation, easing optimization and final code generation.
Scroll to Top