0
0
Compiler Designknowledge~10 mins

Tokens, patterns, and lexemes 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 identify the basic unit of a programming language.

Compiler Design
A [1] is the smallest unit of a program that has a meaning.
Drag options to blanks, or click blank then click option'
Atoken
Bpattern
Clexeme
Dsyntax
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing token with lexeme or pattern.
Thinking syntax is the smallest unit.
2fill in blank
medium

Complete the code to define the role of a pattern in token recognition.

Compiler Design
A [1] defines the rules or structure that a sequence of characters must follow to form a token.
Drag options to blanks, or click blank then click option'
Alexeme
Bsyntax
Cpattern
Dgrammar
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing pattern with lexeme or syntax.
Thinking grammar defines token structure.
3fill in blank
hard

Fix the error in the statement about lexemes.

Compiler Design
A [1] is the actual sequence of characters in the source code that matches a pattern.
Drag options to blanks, or click blank then click option'
Apattern
Blexeme
Csyntax
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up lexeme with token or pattern.
Thinking lexeme is a rule rather than actual text.
4fill in blank
hard

Fill both blanks to complete the dictionary comprehension that maps tokens to their lexemes if the lexeme length is greater than 3.

Compiler Design
{token: lexeme for token, lexeme in token_lexeme_list if len(lexeme) [1] 3 and token [2] 'IDENTIFIER'}
Drag options to blanks, or click blank then click option'
A>
B==
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than for length.
Using inequality instead of equality for token check.
5fill in blank
hard

Fill all three blanks to create a dictionary of tokens and lexemes where lexemes start with a letter and tokens are not 'KEYWORD'.

Compiler Design
{ [1]: [2] for [3], lexeme in token_lexeme_pairs if lexeme[0].isalpha() and [3] != 'KEYWORD' }
Drag options to blanks, or click blank then click option'
Atoken
Blexeme
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping keys and values in the dictionary.
Using wrong variable names in the loop.