$24
Rewrite Systems
Remember our rewriting \game" in the rst lecture.
Given the same input, i.e., a sequence of characters starting with $ and ending with #, and any combination of 0s and 1s in-between, specify a set of rewrite rules that determine whether the string contains the same number of 0s and 1s.
Here is some sample \output": $0011# should be rewritten as $# $1001# should be rewritten as $# $110110# should be rewritten as $11#
$0001100# should be rewritten as $000#
In other words, the $# indicates that the input string has the same number of 0s and 1s. If the string does not contain the same number of 0s and 1s, the resulting string shows how many more 0s or 1s there are in the input string.
Is there at most only a single rewrite rule that can be applied at any point in time during the rewrite process? Explain.
Show the steps of your rewrite system for the input strings $0101# and $10110#.
Regular Expressions
Write a regular expression for numeric constants in C. These are octal, deci-mal, or hexadecimal integers, or decimal or hexadecimal oating-point values. An octal integer begins with 0, and may contain only the digits 0-7. A hex-adecimal integer begins with 0x or 0X, and may contain the digits 0-9 and a/A-f/F. A decimal oating-point value has a fractional portion (beginning
1
with a dot) or an exponent (beginning with E or e). Unlike a decimal in-teger, it is allowed to start with 0. A hexadecimal oating-point value has an optional fractional portion and a mandatory exponent (beginning with P or p). In either decimal or hexadecimal, there may be digits to the left of the dot, the right of the dot, or both, and the exponent itself is given in decimal, with an optional leading + or - sign. An integer may end with an optional U or u (indicating "unsigned"), and/or L or l (indicating "long") or LL or ll (indicating "long long"). A oating-point value may end with an optional F or f (indicating " oat" { single precision) or L or l (indicating "long" { double precision). A decimal oating point number may start with an optional + or sign.
Regular Expressions
Describe the formal languages denoted by the following regular expressions using the English language (e.g.: All strings over the alphabet : : : that have the property : : :):
(( j 1) 0*)*
(0j1)*1(0j1)(0j1)
(00j11)* ((01j10)(00j11)*(01j10)(00j11)*)*
Regular Expressions
Write a regular expression for the following languages.
All strings of a’s, b’s, and c’s that contain no a’s following any b’s.
All strings of a’s, b’s, and c’s that do not contain more than 2 a and 2 b’s.
2