0% found this document useful (0 votes)
14 views13 pages

CDDDDD

Viva questions for cd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views13 pages

CDDDDD

Viva questions for cd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

General Questions

1. What is a compiler?
A compiler is a program that translates high-level source code into low-level machine code
or intermediate code.

2. Explain the purpose of a lexical analyzer.


The lexical analyzer scans the source code and converts it into tokens, removing white
spaces and comments.

3. What is the role of a parser in compiler design?


The parser checks the syntax of the input tokens against a defined grammar and generates
a parse tree.

4. Define a symbol table and its importance.


A symbol table is a data structure used by the compiler to store information about variables,
functions, objects, etc., in the source code.

5. What is the significance of LEX and YACC tools?


LEX is used for lexical analysis, while YACC is used for syntax analysis and parser
generation.

---

Experiment-Specific Questions

Experiment 2: Identify Keywords

6. What is the difference between keywords and identifiers?


Keywords are reserved words with specific meanings, while identifiers are user-defined
names.

7. How is a keyword recognized in the program?


By comparing the input string against a predefined list of keywords.

Experiment 3: Count Keywords


8. How do you count the total number of keywords in a file?
By scanning each word in the file, checking if it matches a keyword, and maintaining a
counter.

9. What data structure is best suited for storing keywords? Why?


An array or hash table, as it allows efficient searching and comparison.

Experiment 4: Count Operators

10. Which operators are typically counted in a program?


Arithmetic (+, -, *, /), logical (&&, ||, !), and relational (<, >, ==) operators.

11. How do you distinguish operators from other symbols in a file?


By comparing characters against a predefined set of operator symbols.

Experiment 5: Character Occurrence

12. How is the frequency of characters calculated?


By iterating through the file and maintaining a count for each character.

13. What modifications are needed to include uppercase characters?


Convert characters to lowercase using tolower() before counting.

Experiment 6: Symbol Table

14. What operations are performed on a symbol table?


Insert, delete, search, and modify entries.

15. Why is searching important in a symbol table?


To retrieve information about variables and identifiers during compilation.

Experiment 7: Valid Inputs with LEX

16. What is the regex for a valid email ID?


[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}.
17. How does LEX validate a mobile number?
Using a regex pattern like [1-9][0-9]{9}.

Experiment 8: Blank Spaces, Words, Lines

18. How does the program count words in a file?


By identifying sequences of characters separated by white spaces or newlines.

19. What are common challenges in line counting?


Differentiating between blank lines and lines containing only white spaces.

Experiment 9: Count Vowels and Consonants

20. How are vowels and consonants distinguished?


By checking each character against sets of vowels (AEIOUaeiou) and consonants.

21. What is the significance of counting vowels and consonants in a file?


It helps in basic linguistic analysis or testing file contents.

Experiment 10: String Recognition with YACC

22. What does a^nb^n represent?


A language where the number of as is equal to the number of bs.

23. Why is recursive parsing used for a^nb^n?


Because it requires matching pairs of symbols in a nested manner.

Experiment 11: Arithmetic Expressions

24. What is operator precedence?


The order in which operators are evaluated in an expression.

25. How does YACC handle precedence?


By defining precedence and associativity rules for operators.
Experiment 12: Grammar Recognition

26. What does the grammar a^n b^n signify?


Strings where a and b occur in equal numbers sequentially.

27. What happens if the input does not match the grammar?
The program displays an error or invalid string message.

Experiment 13: First of Grammar

28. What is the FIRST set of a grammar?


The set of terminals that can appear as the first symbol in the strings derived from a
non-terminal.

29. How is recursion handled in calculating FIRST sets?


By recursively including the FIRST of non-terminals appearing on the right-hand side.

Experiment 14: Lexical Analyzer with Flex

30. What are the advantages of Flex over manual lexical analysis?
Flex is faster, error-free, and automates token generation.

31. What is the significance of state transitions in Flex?


They allow dynamic switching between patterns during analysis.

Experiment 15: Predictive Parsing

32. What is predictive parsing?


A top-down parsing technique that predicts the next production rule using lookahead
symbols.

33. How does LL(1) parsing differ from recursive descent?


LL(1) uses a table-driven approach, while recursive descent relies on explicit recursive calls.
Experiment 16: LALR Parser

34. What does LALR stand for?


Look-Ahead LR parser.

35. Why is LALR parsing efficient?


It reduces the size of parsing tables compared to canonical LR parsers.

---

Conceptual and Advanced Questions

36. What is ambiguity in grammar? How is it resolved?


Ambiguity occurs when a grammar generates multiple parse trees for the same string. It is
resolved by rewriting the grammar or using precedence rules.

37. Explain left recursion. How is it eliminated?


Left recursion occurs when a non-terminal calls itself as the first symbol on the RHS. It is
eliminated by rewriting the grammar into right-recursive form.

38. What is the difference between top-down and bottom-up parsing?


Top-down parsing starts from the start symbol, while bottom-up parsing builds from the
leaves (input symbols) to the start symbol.

39. What is a handle in bottom-up parsing?


A handle is a substring that matches the RHS of a production and can be reduced to a
non-terminal.

40. How does a DFA relate to lexical analysis?


The lexical analyzer uses a DFA to recognize tokens based on character sequences.

41. What is backtracking in parsing?


Revisiting previous decisions in parsing when a match fails, typically used in recursive
descent parsers.

42. What is an intermediate code?


A representation of source code that is independent of both the machine and high-level
language.
43. Why is code optimization important?
To reduce execution time, memory usage, or other resource consumption.

44. What is the difference between syntax and semantic analysis?


Syntax analysis checks the structure of code, while semantic analysis ensures the meaning
is logical and adheres to rules.

45. What is the purpose of error recovery in a compiler?


To continue parsing after encountering errors, allowing the detection of more errors in the
same run.

46. What is the difference between LR and SLR parsing?


LR parsing uses more context (lookahead and state) compared to SLR, which relies only on
the FOLLOW set.

47. What is a production rule?


A rule that specifies how a non-terminal can be replaced by a sequence of terminals and/or
non-terminals.

48. What is epsilon in grammar?


A symbol that represents an empty string in grammar.

49. Explain the role of semantic actions in YACC.


Semantic actions execute code to evaluate expressions or build data structures during
parsing.

50. What are the stages of compilation?


Lexical analysis, syntax analysis, semantic analysis, intermediate code generation,
optimization, and code generation.

Experiment 1: Introduction to the Course

1. What is the objective of studying Compiler Design?


To understand the process of translating high-level code into machine language and learn
various compiler construction techniques.

2. Why is knowledge of compilers crucial for programmers?


It aids in optimizing code, understanding programming language internals, and developing
efficient software.

---

Experiment 2: Identify if a String is a Keyword

3. What defines a keyword in programming?


Keywords are reserved words with specific meanings in a programming language and
cannot be used as identifiers.

4. How does the program identify keywords?


By comparing the input string against a predefined list of keywords stored in an array.

Experiment 3: Count Total Number of Keywords in a File

5. How do you count keywords in a file?


The program scans each word in the file, checks if it matches a keyword, and maintains a
counter for each occurrence.

6. What data structure is used to store the list of keywords?


An array of strings, where each string represents a keyword.

7. What is the role of binarysearch() in this program?


It efficiently searches for a keyword in a sorted array of keywords.

---

Experiment 4: Count Total Number of Operators

8. Which operators are considered in the program?


Arithmetic (+, -, *, /), logical (&&, ||, !), and relational operators (<, >, ==).

9. How does the program differentiate operators from other symbols?


By checking if a character belongs to a predefined set of operator symbols.
10. Why is counting operators in a file important?
It helps analyze the complexity and functionality of a program.

---

Experiment 5: Count the Occurrence of Each Character

11. How is the frequency of each character calculated?


By iterating through the file and maintaining a counter for every character encountered.

12. What types of characters can be ignored or included?


The program can be modified to include or exclude special characters, digits, or uppercase
letters based on requirements.

13. What are common use cases for character frequency analysis?
It is used in text analysis, data compression, and cryptographic systems.

---

Experiment 6: Insert, Delete, and Display Entries in a Symbol Table

14. What is the purpose of a symbol table in compilers?


To store and manage information about variables, functions, and other identifiers during
compilation.

15. What operations can be performed on the symbol table?


Insert new entries, delete existing ones, display the contents, and search for specific entries.

16. How does the program handle duplicate entries?


It checks for duplicates before insertion and prevents them.

---

Experiment 7: Identify Valid Inputs Using LEX


17. How does LEX validate a mobile number?
By using a regular expression pattern such as [1-9][0-9]{9}.

18. What is the regex for a valid email ID?


[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}.

19. Why is input validation important in compilers?


To ensure correct syntax and detect invalid inputs early in the compilation process.

---

Experiment 8: Count Blank Spaces, Words, and Lines

20. What is the purpose of counting spaces, words, and lines in a file?
To analyze the structure and content of a file, often for preprocessing or formatting purposes.

21. How are blank lines differentiated from regular lines?


By checking if a line contains only white spaces or is empty.

22. What challenges arise in counting words accurately?


Handling punctuation, special characters, and multi-line text fragments.

---

Experiment 9: Count Vowels and Consonants in a File

23. How does the program count vowels?


By comparing each character to the set of vowels (a, e, i, o, u).

24. What modifications are needed to handle uppercase letters?


Convert characters to lowercase using tolower() or include uppercase vowels in the
comparison set.

25. What practical applications does this experiment have?


Text processing, linguistic analysis, and educational tools.
---

Experiment 10: Recognize Strings Using YACC

26. What does a^n b^n represent?


A language where the number of as is equal to the number of bs.

27. Why is recursive parsing used for a^n b^n?


To match nested patterns and maintain the balance between a and b.

28. What happens when an invalid string is provided?


The parser generates an error message or terminates with an invalid string output.

---

Experiment 11: Evaluate Arithmetic Expressions

29. How does YACC handle operator precedence?


By defining precedence and associativity rules for operators in the grammar.

30. What is the significance of associativity in expressions?


It determines the order of evaluation for operators with the same precedence.

31. What happens if an operator is missing in the input?


The parser identifies the syntax error and generates an appropriate error message.

---

Experiment 12: Recognize Strings with Grammar

32. What does the grammar a^n b^n signify?


Strings where a and b occur in equal numbers sequentially.
33. What is the role of yyparse() in YACC programs?
It invokes the parser and begins parsing the input based on the defined grammar.

34. How does the program handle empty strings?


By defining epsilon (#) in the grammar, allowing recognition of empty productions.

---

Experiment 13: Find FIRST of a Grammar

35. What is the FIRST set in a grammar?


The set of terminals that can appear as the first symbol in any string derived from a
non-terminal.

36. How does the program handle epsilon (#) in FIRST sets?
It moves to the next symbol in the production when epsilon is encountered.

37. Why is recursion necessary for calculating FIRST sets?


To handle nested non-terminals and compute their FIRST sets accurately.

---

Experiment 14: Implement Lexical Analyzer Using Flex

38. What is the advantage of using Flex for lexical analysis?


It automates the process of token generation and improves efficiency compared to manual
coding.

39. What are state transitions in Flex?


The movement between states based on input characters, enabling dynamic token
recognition.

40. How does Flex handle multi-character tokens?


By using patterns and rules that match sequences of characters.
---

Experiment 15: Implement Predictive Parser

41. What is predictive parsing?


A top-down parsing technique that uses lookahead symbols to select the correct production.

42. What is the role of the LL(1) parsing table?


It maps non-terminals and lookahead symbols to corresponding productions.

43. What are the limitations of predictive parsing?


It cannot handle left-recursive grammars or ambiguous grammars.

Experiment 16: Implement LALR Parser

44. What does LALR stand for?


Look-Ahead LR parser.

45. How does LALR differ from SLR parsing?


LALR uses additional lookahead symbols to resolve ambiguities, making it more powerful
than SLR.

46. Why is LALR parsing preferred over LR parsing?


It reduces the size of parsing tables without sacrificing the ability to parse a wide range of
grammars.

General and Advanced Questions

47. What is the role of intermediate code in a compiler?


It provides a platform-independent representation of the source code, facilitating optimization
and code generation.

48. Explain the importance of error handling in a compiler.


Error handling ensures the compiler can detect, report, and recover from errors to continue
processing the code.

49. What is the difference between syntax and semantic errors?


Syntax errors violate the grammar rules of a language, while semantic errors occur when the
meaning of a program is incorrect.
50. Why is code optimization crucial in compilers?
To improve performance, reduce resource usage, and ensure efficient execution of the
generated machine code.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy