Question 21 Select all of the following statements that are true. Question 21 op
ID: 3828602 • Letter: Q
Question
Question 21
Select all of the following statements that are true.
Question 21 options:
In computer science, an abstract syntax tree (AST) is a tree data structure representation of the abstract syntactic structure of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code. The syntax is "abstract" in not representing every detail appearing in the real syntax. For instance, grouping parentheses are implicit in the tree structure, and a syntactic construct like an if-condition-then expression may be denoted by means of a single node with multiple branches.
Abstract syntax trees (ASTs) are used in program analysis and program transformation systems. For example, an interpreter may be created by visiting each node in an AST and executing operations appropriate for the node. A compiler may be created by visiting each node in an AST and generating machine code corresponding to operations appropriate for the node.
A context-free grammar (CFG) is a formal grammar in which every production rule is of the form
A ::- B
where A is a single nonterminal symbol, and B is a string of terminals and/or nonterminals (B can be empty). A grammar is considered "context free" when its production rules can be applied regardless of the context of a nonterminal. No matter which symbols surround it, the single nonterminal on the left hand side can always be replaced by the right hand side. This is what distinguishes it from a context-sensitive grammar.
A context-sensitive grammar (CSG) is a formal grammar in which the left-hand sides and right-hand sides of any production rules may be surrounded by a context of terminal and nonterminal symbols. Context-sensitive grammars are more general than context-free grammars, in the sense that there are some languages that cannot be described by context-free grammars, but can be described by CSG. A formal language that can be described by a context-sensitive grammar using a linear bounded automaton is called a context-sensitive language.
Save
Question 22 (0.5 points)
The ANSI/ISO C Grammar has a famous Shift/Reduce conflict. (Note: the ANSI/ISO C Grammar is available from multiple sources and is also in Pilot) Which of the following statements are true?
A) The conflict is also known as "the dangling else".
B) The YACC syntax BNF like rule/production that exhibits the Shift/Reduce conflict is contained in the following:
selection_statement
: IF '(' expression ')' statement ELSE statement
| IF '(' expression ')' statement
| SWITCH '(' expression ')' statement
;
C) The YACC syntax BNF like rule/production that exhibits the Shift/Reduce conflict is contained in the following:
compound_statement
: '{' '}'
| '{' block_item_list '}'
;
block_item_list
: block_item
| block_item_list block_item
;
D) When Shift/Reduce conflicts occur, YACC, BISON, and PLY parser generators resolve the conflict by Shifting as opposed to Reducing.
E) The ANSI/ISO C Grammar Shift/Reduce conflict will still exist if the selection_statement rule/production is changed to the following:
selection_statement
: IF '(' expression ')' compound_statement ELSE statement
| IF '(' expression ')' statement
| SWITCH '(' expression ')' statement
;
Question 22 options:
A nd E
A, B, D, and E
B and E
Only C
A, B, C, D, and E
A, B, and D
Question 23 (0.5 points)
Which of the following statements is true:
A) The following regular expression matches real/floating point numbers with exponents:
[-+]?[0-9]*.?[0-9]+([eE][-+]?[0-9]+)?
B) The following regular expression matches valid ANSI/ISO C identifiers:
[A-Za-z_][A-Za-z_0-9]*
C) Regular expressions in general and Lex regular expressions in particular are context free and implementable using finite automata.
D) Natural languages are often context dependent. e.g. "Hit grandma with a club." vs. "Bugs Bunny hit grandma with a club." Supporting this form of context dependence has proven ideal in the specification of programming languages.
E) Scanners are typically implemented using regular expressions and a shift-reduce algorithm to identify tokens.
Question 23 options:
A, B, C, D, and E
Only C
A, B, and C
B and D
A, B, and E
A and B
Save
Question 24 (0.5 points)
Which of the following statements is true:
A) Scheme is a functional programming language and one of the two main dialects of the programming language Lisp.
B) In Scheme, the behavior of (car (car (car '((a b) (c d))))) is undefined or produces and error because (car '((a b) (c d))) is (a b), (car '(a b)) is a, and (car 'a) is undefined.
C) (car (car '((a b) (c d)))) yields 'a and (car (car (cdr '((a b) (c d))))) yields 'b.
D) All of the following are valid ways to write an abs(x) function that returns the absolute value of x:
(define abs
(lambda (n)
(if (< n 0) (- 0 n) n)
)
)
(define abs
(lambda (n)
((if (>= n 0) + -) 0 n)
)
)
(define abs
(lambda (n)
(if (>= n 0) n (- 0 n))
)
)
Question 24 options:
A, B, and D
A, B, and C
B and D
C and D
B and C
a-In computer science, an abstract syntax tree (AST) is a tree data structure representation of the abstract syntactic structure of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code. The syntax is "abstract" in not representing every detail appearing in the real syntax. For instance, grouping parentheses are implicit in the tree structure, and a syntactic construct like an if-condition-then expression may be denoted by means of a single node with multiple branches.
b-Abstract syntax trees (ASTs) are used in program analysis and program transformation systems. For example, an interpreter may be created by visiting each node in an AST and executing operations appropriate for the node. A compiler may be created by visiting each node in an AST and generating machine code corresponding to operations appropriate for the node.
c-A context-free grammar (CFG) is a formal grammar in which every production rule is of the form
A ::- B
where A is a single nonterminal symbol, and B is a string of terminals and/or nonterminals (B can be empty). A grammar is considered "context free" when its production rules can be applied regardless of the context of a nonterminal. No matter which symbols surround it, the single nonterminal on the left hand side can always be replaced by the right hand side. This is what distinguishes it from a context-sensitive grammar.
d-A context-sensitive grammar (CSG) is a formal grammar in which the left-hand sides and right-hand sides of any production rules may be surrounded by a context of terminal and nonterminal symbols. Context-sensitive grammars are more general than context-free grammars, in the sense that there are some languages that cannot be described by context-free grammars, but can be described by CSG. A formal language that can be described by a context-sensitive grammar using a linear bounded automaton is called a context-sensitive language.
Explanation / Answer
Question 21: The true statements are:
b. Abstract syntax trees (ASTs) are used in program analysis and program transformation systems. For example, an interpreter may be created by visiting each node in an AST and executing operations appropriate for the node. A compiler may be created by visiting each node in an AST and generating machine code corresponding to operations appropriate for the node.
d. A context-sensitive grammar (CSG) is a formal grammar in which the left-hand sides and right-hand sides of any production rules may be surrounded by a context of terminal and nonterminal symbols. Context-sensitive grammars are more general than context-free grammars, in the sense that there are some languages that cannot be described by context-free grammars, but can be described by CSG. A formal language that can be described by a context-sensitive grammar using a linear bounded automaton is called a context-sensitive language.
Question 23:
f) A and B
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.