Module 1: Regular Expressions Flashcards
What does a lexer do in programming languages?
The lexer is used to check the syntax of the code in a particular programming language.
It separates the nouns and verbs in a programming language.
What is the input into a lexer?
Inputs that go into a lexer are a series of bytes. (Just the program as bytes)
What are tokens in a programming language and what are they made of?
Tokens are meaningful words in a programming language. Tokens are made up of a series of strings.
What does a compiler writers do?
The compiler writers can understand and enforce the syntax
What is the output of a lexer?
It is a series of strings that make up tokens.
What is a string and how do we define a string over an alphabet ∑ (sigma)?
A string is alphabet symbols together.
A string over an alphabet ∑ (sigma) is a finite sequence of symbols from ∑ (sigma)
How is an ɛ (empty string) defined?
It is a string that is an ɛ empty sequence of symbols.
What happens if you concat a string with an ɛ empty string?
i.e. ɛs = s ɛ
When you concat a string with an ɛ you will get the string back. This does not matter the order of the operation at this point, the empty string can come first or last in the arithmetic operation.
ɛs = s ɛ = s
What does ∑* stand for?
The star operator contains all of the possible possibilities of combinations given a set.
So ∑* contains all of the strings that can be created by combining the alphabet symbols into a string.
Is language L a subset of ∑*?
Yes, language L is a subset of ∑*
Which of the following are infinite?
a. ∑
b. ∑*
c. L
b. ∑* is infinite
c. L can be both finite and infinite
Why do we need regular expressions?
We need regular expressions because tokens are typically specified using regular expressions.
Which of the following apply to regular expressions?
a. Compact
b. Expressive
c. Declarative
d. Vague
e. Precise
f. Widely used
g Hard to generate
h. Easy to generate
a. Compact
b. Expressive (expandable)
e. Precise (not ambiguous, will not match two specific defs)
f. Widely used
h. Easy to generate
What does compact mean in mathematics?
Compact means a set with no holes in it.
Which of the following are rules that a regular expression will follow:
a. Ø
b. ɛ
c. a, where a is not an element in the alphabet
d. a, where a is an element in the alphabet
e. R1 * R2, where R1 and R2 are regular expressions
f. R1 | R2, where R1 and R2 are regular expressions
g. R1 . R2, where R1 and R2 are regular expressions
h. (R), where R is a regular expression
i. R*, where R is a regular expression
a. Ø (null set)
b. ɛ
d. a, where a is an element in the alphabet
f. R1 | R2, where R1 and R2 are regular expressions
g. R1 . R2, where R1 and R2 are regular expressions
h. (R), where R is a regular expression
i. R*, where R is a regular expression