Recall & Review
beginner
What is a regular expression in the context of token patterns?
A regular expression is a sequence of characters that defines a search pattern used to identify tokens in text, such as keywords, identifiers, or symbols in programming languages.
Click to reveal answer
beginner
How do regular expressions help in lexical analysis?
They provide a formal way to describe the patterns of tokens, allowing the lexer to recognize and extract meaningful units from the source code efficiently.
Click to reveal answer
intermediate
What does the regular expression
[a-zA-Z_][a-zA-Z0-9_]* represent?It represents an identifier token pattern: it starts with a letter or underscore, followed by zero or more letters, digits, or underscores.
Click to reveal answer
beginner
Explain the difference between
* and + in regular expressions.* means zero or more repetitions of the preceding element, while + means one or more repetitions.Click to reveal answer
intermediate
Why are regular expressions not suitable for parsing nested structures?
Because regular expressions cannot handle recursive or nested patterns, which require more powerful tools like context-free grammars.
Click to reveal answer
Which regular expression matches a decimal number with optional fractional part?
✗ Incorrect
Option A matches one or more digits followed optionally by a dot and one or more digits, representing a decimal number.
What does the regular expression
if|else|while represent?✗ Incorrect
The expression matches exactly the keywords 'if', 'else', or 'while'.
In regular expressions, what does the symbol
\w typically represent?✗ Incorrect
\w matches letters, digits, and underscore characters.Which of the following is NOT a valid use of regular expressions in token patterns?
✗ Incorrect
Regular expressions cannot match nested structures like parentheses because they lack memory for recursion.
What does the regular expression
[0-9]+ match?✗ Incorrect
The expression matches sequences of one or more digits.
Describe how regular expressions are used to define token patterns in lexical analysis.
Think about how a lexer uses patterns to find meaningful pieces in code.
You got /3 concepts.
Explain the limitations of regular expressions when used for parsing programming languages.
Consider what kinds of language features are too complex for regex.
You got /3 concepts.