Reyza Pratama Komala (1801428384) - LM01
Pada kesempatan kali ini saya akan menjawab soal-soal yang ada dalam buku "CONCEPTS OF Programming Languages (TENTH EDITION)" - ROBERT W. SEBESTA. Chapter 4 Lexical and Syntax AnalysisREVIEW QUESTION
11. Question : Describe the parsing problem for a bottom-up parser.
Answer :bottom up parser only can identifies and processes the text's lowest-level details before processes middle level structures and leaving the highest level overall structure to last
12. Question : Explain why compilers use parsing algorithms that work on only a subset of all grammars.
12. Question : Explain why compilers use parsing algorithms that work on only a subset of all grammars.
Answer :because compiler can use one parsing compiler that work on only subset of all grammars
13. Question : Why are named constants used, rather than numbers, for token codes ?
13. Question : Why are named constants used, rather than numbers, for token codes ?
Answer :
- for the sake of readability of lexical and syntax analyzers.
14. Question : Describe how a recursive-descent parsing subprogram is written for a rule with a single RHS.
- for the sake of readability of lexical and syntax analyzers.
14. Question : Describe how a recursive-descent parsing subprogram is written for a rule with a single RHS.
Answer :
-A recursive-descent subprogram for a rule with a single RHS is relatively
simple. For each terminal symbol in the RHS, that terminal symbol is compared
with nextToken. If they do not match, it is a syntax error. If they match,
the lexical analyzer is called to get the next input token. For each non terminal,
the parsing subprogram for that nonterminal is called.
15. Question : Explain the two grammar characteristics that prohibit them from being used as the basis for a top-down parser.
-A recursive-descent subprogram for a rule with a single RHS is relatively
simple. For each terminal symbol in the RHS, that terminal symbol is compared
with nextToken. If they do not match, it is a syntax error. If they match,
the lexical analyzer is called to get the next input token. For each non terminal,
the parsing subprogram for that nonterminal is called.
15. Question : Explain the two grammar characteristics that prohibit them from being used as the basis for a top-down parser.
Answer : Two grammar characteristics that prohibit top-down parsing:
Direct or indirect Left Recursion.
Direct or indirect Left Recursion.
Tidak ada komentar:
Posting Komentar