























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























































Regular Expressions
(Scanners)
Analysis Synthesis
Identifiers– start with letter or "_" continue with 0 or more letters or
numbers or "_"
Keywords– reserved words that are part of language (if, else, return)– Note: A language doesn't have to have keywords
-^
Operators^ +
-
/
%
&
&&
|
||
Literals– Numeric, string, etc.
-^
Special symbols^ ;
{
}
(
)
Ways to represent strings of characters which followcertain rules– Regular Expression (a formula for matching strings that
follow some pattern
Two notations– Classical– Unix style (recognized by grep/vi/etc.)
[ ] means a character class^ b[aeiou]d
matches
bad,
bed,
bid,
bod,
bud
Note: case sensitive [Bb][AaEeIiOoUu][Dd][a-z]
same as
[abcdefghijklmnopqrstuvwxyz]
[a-zA-Z][_a-zA-Z] A period:
.
or
[.]
How
do
you
describe
bracket
itself?
Match left hand bracket
[[]
Match right land bracket
[]]
Metasymbols– Some same as used in BNF Grammar– Some have different meaning
.^
*****^
[^
]^
^^
$^
+^
/
**
if using as match character)
Some important UNIX style operators (used by grep,
awk, vi, perl etc.)
-^
^ means match at beginning
-^
$ means match at end
inside of a character class ([ ]) means complement of that character class^ ^a
: Match (word | line) starting with "a" [^a]
: Match any character except a small a
$ means match line ending with whatever precedes $sign^ grep
the
myfile
will find all occurences of "the" in myfile
grep
-w
the
myfile
means match "the" as a word
grep
-w
^the
myfile
means match "the" as word only at
beginning of line grep
-w
the$
myfile
means match the "the" as word
only at end of line
Matches everything (except newline \n)!
Write a regular expression to match an identifier [a-zA-Z_][a-zA-Z_0-9]*
-^
Write a regular expression for an unsigned integer [0-9][0-9]*
-^
Unsigned floating point [0-9]+[.][0-9]+
-^
What about [0-9][.][0-9]**
-^
Allows
Match any character not a vowel [^aeiouAEIOU]
-^
Match any uc or lc consonant [b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z]
-^
To include ^ put it somewhere other than thebeginning
-^
Regular Expressions are used in grep, sed, awk, perl,vi, shells, lex, yacc– Note: Each of these may have its own slightly different rules
Write a regular expression consisting of 0’s and 1’swhich
may
have a 0 but whenever it occurs it
must
be
followed by a 1
-^
An identifier that starts with a lower case letter orunderscore and followed by one or more of lowercase letters and digits and underscores. A letter or adigit must follow an underscore.
-^
A string that consists of at least 3 consecutive 0’s
The^ The ButtonButton
mmmm^ mmmm Motor Running^ Motor Running
L
L
The^ The ButtonButton
"Click"^ "Click"
L
L