Which of the following statement is correct about parsing?1. Top-down ...
- Top down parsing expands the start symbol to the required string needed where as in bottom up parse string reduces to start symbol by handle purring.
- Top down parser also known as recursive descent parser i.e. uses recursive procedure, where as bottom up parser user stack and input buffer.
- Backbacking is required in top-down parser but not in bottom up.
This question is part of UPSC exam. View all Computer Science Engineering (CSE) courses
Which of the following statement is correct about parsing?1. Top-down ...
Explanation:
Parsing is the process of analyzing a string of symbols to determine its grammatical structure according to a given grammar. It is an important step in the compilation process where the input program is checked for syntactic correctness and transformed into an internal representation for further processing.
1. Top-down parsing expands the start symbol to the required string needed whereas in bottom-up parsing reduces the syntax to the start symbol.
- Top-down parsing starts with the start symbol of the grammar and tries to build a parse tree by expanding the non-terminals in a left-to-right manner until the input string is derived.
- Bottom-up parsing, on the other hand, starts with the input string and reduces it to the start symbol by applying production rules in a right-to-left manner.
- Therefore, the first statement is correct.
2. Top-down parsing is implemented using the set of recursive procedures and implementation of bottom-up parsing is done using the stacks and input buffer.
- Top-down parsing can be implemented using recursive procedures or using a predictive parsing table. Recursive descent parsing is a top-down parsing technique where each non-terminal has a corresponding recursive procedure to handle it.
- Bottom-up parsing, on the other hand, is implemented using a stack and input buffer. The stack is used to keep track of the intermediate parsing states and the input buffer represents the remaining input symbols.
- Therefore, the second statement is correct.
3. Backtracking is required for both bottom-up and top-down parsing implementation.
- Backtracking is a technique used in parsing when a choice made during parsing leads to a dead-end or a parsing error. In such cases, the parser backtracks to the previous decision point and explores alternative choices.
- Backtracking is commonly used in top-down parsing when it encounters multiple choices for a non-terminal symbol. It tries one choice and if it doesn't lead to a successful parse, it backtracks and tries another choice.
- Bottom-up parsing techniques like LR parsing usually do not require backtracking as they use deterministic parsing tables to guide their decisions.
- Therefore, the third statement is incorrect.
Based on the above explanations, the correct answer is option A.
To make sure you are not studying endlessly, EduRev has designed Computer Science Engineering (CSE) study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Computer Science Engineering (CSE).