0
0
Compiler Designknowledge~10 mins

Parse trees and derivations in Compiler Design - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to represent the root of a parse tree.

Compiler Design
root = ParseTreeNode([1])
Drag options to blanks, or click blank then click option'
Aexpression
Btoken
Cgrammar
Dsyntax
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'grammar' or 'syntax' instead of a token for the root node.
2fill in blank
medium

Complete the code to create a derivation step from a non-terminal to a production.

Compiler Design
derivation = DerivationStep([1], production_rule)
Drag options to blanks, or click blank then click option'
Anon_terminal
Bterminal
Ctoken
Dleaf
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing terminal and non-terminal symbols in derivations.
3fill in blank
hard

Fix the error in the code to correctly build a parse tree node with children.

Compiler Design
node = ParseTreeNode(symbol=[1], children=children_list)
Drag options to blanks, or click blank then click option'
Anon_terminal
Btoken
Cproduction
Dterminal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'token' or 'terminal' for nodes that have children.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension mapping non-terminals to their productions.

Compiler Design
{ [1]: [2] for [1] in grammar.non_terminals }
Drag options to blanks, or click blank then click option'
Ant
Bproduction_list
Csymbol
Drule
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'symbol' or 'rule' as keys or values incorrectly.
5fill in blank
hard

Fill all three blanks to filter productions that derive a terminal symbol.

Compiler Design
[prod for prod in productions if prod.[1] == [2] and prod.[3]]
Drag options to blanks, or click blank then click option'
Aleft_side
Bterminal
Cis_terminal
Dright_side
Attempts:
3 left
💡 Hint
Common Mistakes
Checking left_side instead of right_side.
Confusing property names.