ArticleDirectory
- 2.2.1 definition of Regular Expressions
- 2.2.2 extensions to regular expressions Regular Expression Extension
- 2.2.3 Regular Expressions for programming lanaguage tokens
Chapter 2
Language generated by regular expression is written as L (r ).
This language depends on the character set that is available. Set elements are
Reffered as symbols. This set of legal symbols is called the alphabet and is usually
Written as the Greek symbol Sigma.
2.2.1 definition of Regular Expressions
1. Basic Regular Expression
2. Choice of alternatives: |
3. concatenation: Rs
4. Repetition: Kleene closure R *
5. Parentheses :()
Anban
Pumping Lemma
2.2.2 extensions to regular expressions Regular Expression Extension
1. One or more one or more repetitions: +
2. Any character any character :.
3. character range: a range of characters: [A-Z]
4. Any character not in a given set: [^ ABC]
5. Optional?
2.2.3 Regular Expressions for programming lanaguage tokens
1. Reserved Words, keywords: while, if
2. special symbols: ++,: =
3. Identifiers: sequences of letters and digits begin with a letter
4. literals: Numeric constants, 42, 3.14159, string literals, "Hello, world", 'A'
1) numbers:
Nat = [0-9] +
Signednat = (+ | -)? Nat
Number = signednat ("." nat )? (E signednat )?
2) Reserved Words and identifiers
Reserved = if | while | Do |...
Letter = [A-Za-Z]
Digit = [0-9]
Identifier = letter (letter | digit )*
3) comments:
/**/Ad hoc method
(* This is (* A Modula-2 *) Comment *)
We have noted in expample 2.3 that regular expressions
Cannot express counting operations. In practice, we use a simple Conter
As an ad hoc solution to this problem (see the exercises ).
4) ambiguity, white space, and lookahead
1. disambiguating rules
Principle of longest substring
Token delimiters
Free format, fixed format, offside rule (use indent to format)