Module 2: Syntax Analysis and Parsing Flashcards
What is the goal of syntax analysis?
a. Transform the sequence of tokens from a lexer into something useful.
b. Make sure that each of the words in a string is real words.
a. Transform the sequence of tokens from a lexer into something useful.
True or False: Regular expressions are sufficient to capture all programming constructs?
a. True
b. False
b. False
What is each row in context-free grammars called?
a. row
b. production
c. column
d. element
b. production
What is the correct syntactical order for context-free grammars?
a. Right arrow
b. Non-terminals
c. Non-terminals and terminals
b. Non-terminals on the left
a. Right arrow
c. Non-terminals and terminals on the right
How can you tell the difference between terminals and non-terminals?
a. Terminals are longer names
b. Terminals start with an upper case and non-terminals will be lowercase and are tokens
c. Terminals will be all lowercase and are tokens and non-terminals will start with an upper case.
d. You can’t tell the difference without any context
c. Terminals will be all lowercase and are tokens and non-terminals will start with an upper case.
What letter is used for the start of a non-terminal?
a. A
b. S
c. T
d. N
b. S
What production is equivalent to:
S -> ɛ
S -> (S)
a. S -> (S)
b. S -> (ɛ)S
c. S -> (S)ɛ
d. S -> (S) | ɛ
d. S -> (S) | ɛ
Two rules can be combined using the bar symbol.
What is the derivations of the CFG for:
S -> (S) | ɛ
S => ɛ
S => (S) => (ɛ) => ()
S => (S) => ((S)) => ((ɛ)) => (())
What is the derivations of the CFG for:
Exp -> Exp + Exp
Exp -> Exp * Exp
Exp -> NUM
Exp => Exp * Exp => Exp * 3 => Exp + Exp * 3 => Exp + 2 * 3 => 1 + 2 * 3
What are the two different ways of deriving CFG?
a. Leftmost
b. Center Out
c. Rightmost
d. Full stack
a. Leftmost
c. Rightmost
What is a parse tree?
a. Creating a tree from the leftmost or rightmost derveriations of CFG.
b. A tree that shows how to parse a parser
c. A flat file showing a CFG
a. Creating a tree from the leftmost or rightmost derveriations of CFG.
What are the major problems in parsing?
a. Ambiguous grammars
b. Parsing is super efficient
c. Parsing can be inefficient
d. There is never more than one way to parse data.
a. Ambiguous grammars
c. Parsing can be inefficient
Can parsing imply operator precedence rules?
a. True
b. False
a. True
When is a grammar considered to be ambiguous?
a. When there is two different leftmost derivations
b. When there is two different rightmost derivations
c. When there is two different parse trees for any string in the grammar
d. All of the above
d. All of the above
What are the different types of turning trees into parse trees?
a. Bottom up
b. Top down
c. Left to right
d. Right to left
a. Bottom up
b. Top down