0
0
Compiler Designknowledge~10 mins

Regular expressions for token patterns 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 match an identifier starting with a letter followed by letters or digits.

Compiler Design
pattern = r"[1]"
Drag options to blanks, or click blank then click option'
A"\d+"
B"[0-9]+"
C"[a-zA-Z][a-zA-Z0-9]*"
D"[a-z]+"
Attempts:
3 left
💡 Hint
Common Mistakes
Using digits at the start of the pattern
Not allowing digits after the first character
2fill in blank
medium

Complete the regular expression to match an integer literal consisting of one or more digits.

Compiler Design
pattern = r"[1]"
Drag options to blanks, or click blank then click option'
A"[a-zA-Z]+"
B"[0-9]*"
C"[a-z]+"
D"[0-9]+"
Attempts:
3 left
💡 Hint
Common Mistakes
Using * which allows zero digits
Using letters instead of digits
3fill in blank
hard

Fix the error in the regular expression to correctly match a floating-point number with optional decimal part.

Compiler Design
pattern = r"\d+[1]\d*"
Drag options to blanks, or click blank then click option'
A"."
B"\."
C"\\."
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping the dot, causing it to match any character
Using too many backslashes
4fill in blank
hard

Fill both blanks to create a regex that matches an identifier starting with a letter and containing letters, digits, or underscores.

Compiler Design
pattern = r"[1][2]*"
Drag options to blanks, or click blank then click option'
A"[a-zA-Z]"
B"[0-9]"
C"[a-zA-Z0-9_]"
D"[_]"
Attempts:
3 left
💡 Hint
Common Mistakes
Allowing digits or underscores as the first character
Not including underscore in the second part
5fill in blank
hard

Fill all three blanks to create a regex that matches a string literal enclosed in double quotes, allowing escaped quotes inside.

Compiler Design
pattern = r"\"[1][2]*[3]\""
Drag options to blanks, or click blank then click option'
A"(\\.|[^"]"
B"(\\.|[^"])*"
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping quotes inside the string
Not matching zero or more characters inside quotes