0
0
Compiler Designknowledge~10 mins

Context-free grammars 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 define a simple production rule in a context-free grammar.

Compiler Design
S -> [1]
Drag options to blanks, or click blank then click option'
A"aSb"
B"a"
C"ab"
D"b"
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a string with multiple symbols which is not a single production.
Using non-terminal symbols on the right side without proper notation.
2fill in blank
medium

Fill both blanks to show a recursive production rule for balanced parentheses.

Compiler Design
P -> [1] P [2] | ""
Drag options to blanks, or click blank then click option'
A"["
B"("
C"{"
D")"
Attempts:
3 left
💡 Hint
Common Mistakes
Using mismatched parentheses symbols.
Forgetting the empty string alternative.
3fill in blank
hard

Fix the error in the production rule for arithmetic expressions.

Compiler Design
E -> E [1] T | T
Drag options to blanks, or click blank then click option'
A"+"
B"-"
C"*"
D"/"
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication or division instead of addition.
Using an operator that does not fit the grammar rule.
4fill in blank
hard

Fill both blanks to complete the production rule for identifiers starting with a letter followed by letters.

Compiler Design
ID -> [1] | [1] [2]
Drag options to blanks, or click blank then click option'
Aletter
B"digit"
CID
D"number"
Attempts:
3 left
💡 Hint
Common Mistakes
Using digits as the first symbol.
Not using recursion to allow multiple characters.
5fill in blank
hard

Fill all three blanks to define a production rule for a simple if-statement.

Compiler Design
Stmt -> "if" [1] "then" [2] [3]
Drag options to blanks, or click blank then click option'
Acondition
BStmt
C"else"
Dexpression
Attempts:
3 left
💡 Hint
Common Mistakes
Using "expression" instead of "condition".
Omitting the "else" keyword.