Concepts of Programming Languages 10th Edition – Robert W. Sebesta
Lecturer : Tri Djoko Wahjono
Review Questions (Randomly 8 of 27)
- What are three reasons why syntax analyzers are based on grammars? (Number 1)
– First : Grammars are clear and concise.
Second : The grammar description can be use as a direct basis for the analyzer.
Third : Grammar are modular / easy to maintain.
- Explain three reasons why lexical analysis is separated from syntax analysis. (Number 2)
– Simplicity, Techniques for lexical analysis are less complex than those required for syntax analysis. Efficiency, Although it pays to optimize the lexical analyzer, because lexical analysis requires a significant portion of total compilation time. Portability, Because the lexical analyzer reads input program files and often includes buffering of that input, it is somewhat platform dependent.
- Define lexeme and token. (Number 3)
– A Lexeme is a string of characters that is a lowest-level syntatic unit in the programming language. These are the “words” and punctuation of the programming language. A Token is a syntactic category that forms a class of lexemes. These are the “nouns”, “verbs”, and other parts of speech for the programming language.
- What is a state transition diagram? (Number 6)
– State transition diagrams have been used right from the beginning in object-oriented modeling. The basic idea is to define a machine that has a number of states (hence the term finite state machine).
- What are the two distinct goals of syntax analysis? (Number 8)
– To detect syntax errors in a given program, and to produce a parse tree or possibly the information required to build such a tree for a given program.
- Describe the pairwise disjointness test. (Number 17)
– The pairwise test try to test whether a parsing subprogram can determine which RHS is being parsed on the basis of the next token of input.
- What is left factoring? (Number 18)
– Left factoring is the action taken when a grammar leads backtracking while marking parsing or syntax tree.
- Describe three advantages of LR parsers. (Number 23)
– They can be built for all programming languages. They can detect syntax errors as soon as it possible in a left-to-right scan. The LR class of grammars is a proper superset of the class parsable by LL parsers.