Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS314

Assignment 1

1    Rewrite Systems

(a)  Given the same input, i.e., a sequence of characters starting with v and ending with #, and any combination of 0s and 1s in-between, specify a set of rewrite rules that determine whether the string contains an even number of 0s.

Here is some sample “output”:

v0011# should be rewritten as 0011 → A

v10001# should be rewritten as 10001 → B

v110110# should be rewritten as 110110 → A

v0001100# should be rewritten as 0001100 → B

(b) Is there at most only a single rewrite rule that can be applied at any point in time during the rewrite process  (using  your own rewriting rules)? Explain.

(c)  Show the steps of your rewrite system for the input strings v0101# and v1000#.

2    Regular Expressions

Write a regular expression that is similar to the regular expression used to de- scribe hexadecimal numeric constants in C. These are hexadecimal integers, or hexadecimal floating-point values. A hexadecimal integer begins with 0x or 0X, and may contain the digits 0-9 and a/A-f/F. A hexadecimal floating- point value has an optional fractional portion and a mandatory exponent (beginning with P or p).  In 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 floating-point value may end with an optional F or f (indicating ”float” – single precision) or L or l (indicating ”long” – double precision).

3    Regular Expressions

Write a regular expression for the following languages.

(a) All strings of a’s, b’s, and c’s that start with aba.

(b) All strings of a’s, b’s, and c’s that do not contain more than 1 a, 1 b, 1 c.