Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1[10pt] a) (5pt) Build a regular expression that captures all non-empty

ID: 3890518 • Letter: P

Question

Problem 1[10pt] a) (5pt) Build a regular expression that captures all non-empty sequences of letters other than the string “cse”. For your convenience, you may use a ! operator for this problem. The operator takes a set of letters as argument and matches any other letterFor instance, !(abc) matches any letter other than a, b and c. Use to match any letter. b) (5pt) Create a regular expression for the language consisting of declarations (in a single line) of variables of type int in C. Multiple variables can be declared in a single declaration, separated by commas, and each can have an optional initial value (given by a constant. A declaration is terminated by a semicolon. For example, the following two lines are both valid declarations: int x=3; int x, y=5, z ; For your convenience, use symbols ID and N for identifiers and integers respectively in your RE. More over, assume there is no space in the definition except the one after int. Use s for the space character.

Explanation / Answer

1

a: logic:
   accept all words of lenght 1 and length 2: (..?)
   accept all words of length 3 except cse(!(c)!(s)!(e))
   accept all words of length 4 or more(....+)
   (..?)|(!(c)!(s)!(e))|(....+)

b
int ID(=N)?(,ID(=N)?)?;