chapter 3 Flashcards
________ is the process of constructing a syntactic structure (parse tree) from a stream of tokens
Answer: Parsing
The parser receives a string of tokens from the ________ analyzer and verifies if the string of token names can be generated by the grammar for the source language.
Answer: lexical
Which phase of the compiler constructs the abstract syntax tree?
a) Lexical Analysis
b) Syntax Analysis
c) Semantic Analysis
d) Code Generation
Answer: b) Syntax Analysis
what does the The parser in syntax analysis perform?
context free syntax analysis,
guides context-sensitive analysis,
constructs an intermediate representation, produces meaningful error messages,
and attempts error correction.
________ parsing methods include the CYK algorithm and Earley’s algorithm.
Answer: Universal
what are the three general types of parsers for grammars?
universal,
top-down, and
bottom-up
Which of the following parsers build parse trees from the top (root) to the bottom (leaves)?
a) Bottom-Up Parsers
b) Top-Down Parsers
c) CYK Parsers
d) Earley Parsers
Answer: b) Top-Down Parsers
Universal parsing methods are, too inefficient to use in production compilers.
t
Compilers assist programmers in identifying and locating ________.
Answer: errors
The information which syntax analysis phase gets from the previous phase (lexical
analysis) is _________ and _________
- whether a token is valid or not and
- which class of tokens does it belong to.
it is beyond the capabilities of the syntax analysis phase to settle issues
like:
Whether or not a variable has already been declared?
Whether or not a variable has been initialized before use?
Whether or not a variable is of the type on which the operation is allowed?
what are Error handler goals
Report the presence of errors clearly and accurately
Recover from each error quickly enough to detect subsequent errors
Add minimal overhead to the processing of correct programs
Which of the following is not a common programming error?
a) Lexical Error
b) Syntactic Error
c) Semantic Error
d) Predictive Error
Answer: d) Predictive Error
In ________ , the parser discards input symbols until a designated synchronization token is found.
Answer: Panic Mode recovery
______ errors include misspellings of identifiers, keywords, or operators
Lexical
_______ errors include misplaced semicolons or extra or missing braces; that
is, “{“ or “}.”
Syntactic
_____ errors include type mismatches between operators and operands.
Semantic
what are The four main strategies in error handling:
a) Panic Mode Recovery
b) Phrase Level Recovery
c) Error Productions
d) Global Correction
Which error recovery strategy involves making local corrections to allow the parser to continue?
a) Panic Mode Recovery
b) Phrase Level Recovery
c) Error Productions
d) Global Correction
Answer: b) Phrase Level Recovery
________ augment grammar with productions that generate erroneous constructs.
Answer: Error Productions
_____ Simplest method of recovery used by most parsing methods.
Panic Mode Recovery
Panic mode recovery will lead to an infinite loop.
f
________ Replaces a prefix of remaining input by some string that allows the parser to continue.
Phrase Level Recovery
Care should be taken by the replacements , not to lead to infinite loops in ______ recovery
Phrase Level Recovery
Which error recovery strategy identifies and corrects errors to obtain a globally least-cost correction?
a) Panic Mode Recovery
b) Phrase Level Recovery
c) Error Productions
d) Global Correction
Answer: d) Global Correction
A context-free grammar (CFG) consists of ________, ________, ________ and ________
terminals,
non-terminals,
production rules, and
a start symbol.
Regular expressions can not be used for syntax analysis (specification of grammar)
t
Which component of a CFG are the basic symbols from which strings are formed?
a) Terminals
b) Non-terminals
c) Production Rules
d) Start Symbol
Answer: a) Terminals aka tokens
Non-terminals are ________ denoting _____
Answer: syntactic variables , sets of strings.
CFG is aka ______
Backus-Naur-Form(BNF) description.
Which part of a CFG defines how syntactical constructs may be built from terminals?
a) Terminals
b) Non-terminals
c) Production Rules
d) Start Symbol
Answer: c) Production Rules
______ impose a hierarchical structure on the language
Non-terminals
________ is a sequence of replacements of non-terminal symbols with strings of terminals and non-terminals.
Answer: Derivation
explain production rules
The left-hand side (head) of each rewriting rule is a single non- terminal.
The right-hand side (body) of each rewriting rule is a string of terminals and/or non-terminals
Example: E—-> E+T
- Terminal: T
- Non-Terminal: E,T
A hierarchical structure representing the syntactic structure of the input based on a CFG is known as a ________.
a) Parse Tree
b) Derivation
c) Syntax Graph
d) Semantic Tree
Answer: a) Parse Tree
what are the 2 types of derivation
a) Leftmost Derivation
b) Rightmost Derivation
Ambiguity in CFG occurs when a string can have more than one valid ________ or ____
Answer: parse tree, derivation
Some derivations are neither leftmost nor rightmost
t
Given S ⇒ α - form of G.
If α contains non-terminals, it is called _____
a sentential
Given S ⇒ α - form of G.
If α doesn’t contain non-terminals, it is called _____
a sentence of G