Lexical analysis is performed by:ParserScannerCode GeneratorAssemblerB) ScannerScanner breaks source code into tokens.
Which phase checks syntax errors?Lexical AnalysisSyntax AnalysisSemantic AnalysisCode GenerationB) Syntax AnalysisSyntax analysis uses parsing to check grammar of code.
Intermediate code generation helps in:Machine independenceSyntax checkingTokenizationError reportingA) Machine independenceIntermediate code makes it easier to target multiple architectures.
Which parser is used in compilers for parsing expressions?Recursive DescentShift-ReduceOperator PrecedenceAll of the aboveD) All of the aboveCompilers can use different parsing techniques based on grammar.
Symbol table is used to store:KeywordsIdentifiers 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?Code GenerationLexical AnalysisSyntax AnalysisSemantic AnalysisB) Lexical AnalysisLexical analysis scans source code and converts it into tokens.
Intermediate code generation is done to:Directly produce machine codeImprove 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:Machine instructionsInformation 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?LL ParsingLR 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:High-level codeIntermediate representationTarget assembly codeSyntax treeC) Target assembly codePeephole optimization improves machine code by replacing inefficient instruction sequences.
Syntax tree is generated during:Lexical AnalysisSemantic AnalysisSyntax AnalysisCode OptimizationC) Syntax AnalysisSyntax analysis (parsing) converts tokens into a parse tree representing grammatical structure.
Which phase detects type mismatch errors?Code GenerationLexical AnalysisSemantic AnalysisOptimizationC) Semantic AnalysisSemantic analysis ensures type correctness and logical consistency.
A compiler that produces machine-independent code is called:Cross CompilerNative 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?Constant FoldingDead Code EliminationStrength ReductionTokenizationD) TokenizationTokenization is a lexical analysis step, not an optimization technique.
Parsing table is used in:Lexical AnalysisParsingCode GenerationSymbol Table ManagementB) ParsingParsing table guides the parser to build syntax trees based on grammar rules.
Lexical analyzer outputs:Parse TreeTokensIntermediate CodeMachine CodeB) TokensLexical analysis breaks source code into tokens.
Intermediate code generation is done to:Reduce code sizeImprove portabilityDirectly produce machine codeSpeed up parsingB) Improve portabilityIntermediate code allows retargeting to multiple machine architectures.
Peephole optimization focuses on:Large code blocksSmall set of instructionsParsing tableSyntax treeB) Small set of instructionsPeephole optimization improves short instruction sequences.
YACC is used for:Code GenerationLexical AnalysisParsingSymbol Table ManagementC) ParsingYACC (Yet Another Compiler Compiler) generates parsers from grammar rules.
Which table stores variable information during compilation?Parse TableSymbol TableLookup TableHash TableB) Symbol TableSymbol table keeps track of variables, types, and scopes.
Peephole optimization is performed in:Lexical AnalysisIntermediate Code OptimizationSemantic AnalysisParsingB) Intermediate Code OptimizationPeephole optimization improves code by looking at small instruction sequences.
Left recursion is eliminated in:ParsingCode GenerationLexical AnalysisSymbol Table ManagementA) ParsingLeft recursion must be removed for top-down parsers to work.
Which parser uses lookahead symbols?LL(1)LR(0)SLRCanonical LRA) LL(1)LL(1) parser uses one-token lookahead for decision making.
Semantic Analysis checks:Grammar ErrorsMeaning of StatementsTokenizationCode ExecutionB) Meaning of StatementsSemantic analysis validates type compatibility, declarations, etc.
Backpatching is used in:Code GenerationIntermediate Code GenerationParsingLexical AnalysisB) Intermediate Code GenerationBackpatching fills forward jumps once target addresses are known.
exical analysis converts source code into:TokensParse Trees Intermediate Code Machine CodeA) Tokens Lexical analyzer breaks source into tokens for parser.
Which grammar removes ambiguity?Context-Free GrammarContext-Sensitive GrammarRegular GrammarUnambiguous GrammarD) Unambiguous GrammarAmbiguity-free grammar ensures unique parse trees.
Intermediate code is generated to:Improve parsing speedAchieve machine independenceReduce errorsDirectly execute codeB) Achieve machine independenceIntermediate code provides portability before final code generation.
Which parsing is also called shift-reduce parsing?Top-Down ParsingBottom-Up ParsingLL ParsingPredictive ParsingB) Bottom-Up ParsingBottom-up parsers shift input symbols and reduce productions.
A symbol table stores:Grammar rulesVariable names and attributesIntermediate codeError messagesB) Variable names and attributesSymbol table records identifiers with their type and scope.
The first phase of a compiler is:Syntax analysisLexical analysisSemantic analysisCode generationB) Lexical analysisLexical analysis scans input and produces tokens.
Intermediate code is generated to:Make compilation fasterAchieve portabilitySkip semantic checksIncrease errorsB) Achieve portabilityIntermediate code makes optimization and machine translation easier.
Which parser uses backtracking?LL(1)LRRecursive descent Operator precedenceC) Recursive descentRecursive descent parsing often requires backtracking.
Peephole optimization is a type of:Machine-independent optimizationMachine-dependent optimizationCode parsingError correctionB) Machine-dependent optimizationPeephole optimization looks at small code patterns for replacement.
Tokens are recognized in which phase?Lexical AnalysisParsingOptimizationLinkingA) Lexical AnalysisLexical analysis divides source code into tokens.
Which parsing method uses backtracking?LL(1)Recursive DescentLROperator PrecedenceB) Recursive DescentRecursive descent parsing may involve backtracking.
Which optimization reduces redundant calculations?Dead code elimination Common subexpression eliminationLoop unrollingCode motionB) Common subexpression eliminationIt avoids repeated evaluation of the same expression.
Which parser is used in YACC?LL(1)LRRecursive descentOperator precedenceB) LRYACC uses LR parsing.
Which phase checks type errors?Syntax AnalysisLexical AnalysisSemantic AnalysisCode OptimizationC) Semantic AnalysisSemantic analysis ensures type compatibility.
DAG in optimization stands for:Directed Acyclic GraphData Allocation GraphDirect Access GroupDynamic Allocation GraphA) Directed Acyclic GraphDAG helps in eliminating redundant expressions.
Lexical analysis produces:TokensSyntax treeIntermediate codeMachine codeA) TokensLexical analyzer converts characters into tokens.
Operator precedence parsing avoids:AmbiguityLeft recursionShift-reduce conflictsLeft factoringB) Left recursionPrevents infinite recursion in parsing.
Intermediate code is generated to:Optimize storageProvide portabilityReduce compile timeRemove redundancyB) Provide portabilityMakes code adaptable across platforms.
Symbol table stores:Only constantsVariable names and attributesTokens onlyIntermediate codeB) Variable names and attributesSymbol tables map identifiers to details.
Left recursion in grammar causes:Infinite recursion in top-down parserShift-reduce conflictAmbiguityDeadlockA) Infinite recursion in top-down parserTop-down parsers cannot handle left recursion.
Lexical analysis converts source code into:Syntax treesTokensIntermediate codeMachine codeB) TokensLexer breaks code into token streams.
Which parser uses lookahead symbols?LR parserLL parserOperator precedence parserAll of the aboveD) All of the aboveParsers often require lookahead for decisions.
Intermediate code is generated to:Increase execution speedMake compiler portableReduce memoryOptimize cacheB) Make compiler portableIntermediate code allows retargeting to many machines.
Peephole optimization is a type of:Code generationLocal optimizationSyntax analysisSemantic analysisB) Local optimizationIt replaces inefficient code patterns.
Which phase ensures variables are declared before use?Lexical analysisSyntax analysisSemantic analysisOptimizationC) Semantic analysisSemantic checks enforce correctness rules.
Which phase of compiler checks syntax errors?Lexical analysisSyntax analysisSemantic analysisCode generationB) Syntax analysisSyntax analyzer ensures grammar correctness.
Intermediate code is generated for:PortabilityDebuggingLinkingOptimization onlyA) PortabilityIntermediate code allows easier retargeting.
Lexical analysis outputs:TokensParse treeMachine codeIntermediate codeA) TokensLexical analysis breaks input into tokens.
Peephole optimization is done at:High-level codeIntermediate codeAssembly/machine codeSource codeC) Assembly/machine codePeephole optimization improves small sections of code.
Which parsing method is used in YACC?LL(1)Recursive descentOperator precedenceNoneD) NoneYACC uses LR parsing technique.
A symbol table is used for:Error handlingIdentifier managementMachine code generationTokenizationB) Identifier managementSymbol tables store variable and function information.
Semantic analysis checks:GrammarMeaning of statementsToken streamCode optimizationB) Meaning of statementsSemantic analysis verifies type and consistency.
Which optimization technique eliminates common subexpressions?Constant foldingDead code eliminationCommon subexpression eliminationLoop unrollingC) Common subexpression eliminationIt avoids redundant computations.
Bootstrapping a compiler means:Writing a compiler in assemblyCompiler compiling itselfUsing another compilerWriting in machine codeB) Compiler compiling itselfBootstrapping allows self-compilation for portability.
The output of lexical analysis is:TokensSyntax treeMachine codeBytecodeA) TokensLexical analyzer breaks input into tokens.
Left recursion in grammar affects:ParsingLexical analysisSemantic analysisCode optimizationA) ParsingLeft recursion leads to infinite recursion in top-down parsers.
Intermediate code generation produces:Source codeTarget codeAbstract representationTokensC) Abstract representationIntermediate code is machine-independent.
Which optimization eliminates common sub-expressions?Loop unrollingDead code eliminationConstant foldingCommon subexpression eliminationD) Common subexpression eliminationIt avoids recomputing identical expressions.
Which phase of the compiler is responsible for lexical analysis?ParserScannerOptimizerCode 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 optimize machine instructionsTo 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.