TEST 3 Flashcards
Language
language defines a set of strings of comprised of characters from an “alphabet” of symbols – defines valid words and combos of words in a sentence
Regular language
a language that can be formally described using a finite state machine
Finite state machine
an abstract model of computation comprised of states + transitions
Regular expression
a pattern used to search for a match within a string of text
What two properties must hold in order for a finite state machine to be considered deterministic?
- Every transition requires that an event occur (char. be consumed)
2.There is at most one transition on the same event (character) out
of a particular state
|
or
[]
any single letter in word brackets
[-]
match one single character from contgious range **a-c valid but c-a is not
\
treat the next character literally, rather than as an operator; ie \“[cat]”\ then [cat] will be accepted
why double \ not single
bc \ has special meaning as an example ie if we want to do a literal double qoute in a string and not end the string there we use \ to escape the literal
?
match 0 or 1 instances of the preceding character or group;
*
match 0 or more instances of the preceding character or group;
+
match 1 or more instances of the preceding character or group;
what is difference between + and *
+ means at least 1 * means can be 0
Order of operations
- \
- [] including -
- ()
- ?
- concatenation (valid regex back to back)
- |
public String substring(int startIdx)
returns the substring
from startIdx (inclusive) to the end
String substring(int startIdx, int endIdx)
returns the substring from startIdx (inclusive) to endIdx (exclusive)
public int indexOf(String str)
returns the start index of the
first occurrence of str in the string; returns -1 if str is not found
public String replaceAll(String regex, String new)
a copy of the original string with every substring that matches regex replaced by new– can pass string literal or reg ex – reg ex adds additonal flexibality
sentence
a sequence of strings in the language
language
defines a set of strings of comprised of characters from an “alphabet” of symbols (does not have to be A-Z)
sentence
a sequence of strings in the language
grammar
definition of the structure of a valid sentence in the language
syntax
the structural validity of a sentence
semantics
the meaning of a sentence
int x = “abc is
is syntactically valid, but semantically invalid