Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[6 pts] C has three forms of integer constants: decimal, octal, and hexadecimal. The value 30 is expressed as 30, 036, and Oxle in
[6 pts] C has three forms of integer constants: decimal, octal, and hexadecimal. The value 30 is expressed as 30, 036, and Oxle in these forms, respectively. We have shown in lecture that the decimal and octal constants can be defined by regular expressions: octal = 0[0-7] + decimal = 0 | [1-9] [0-9]* (a) [1] Give a regular expression for hexadecimal constants. (Assume only lower cases letters are used.) (b) [3] Now consider two subsets of integer constants: i. the set of even constants (e.g. 10, 012, and 0xc are three such constants, all have an even value of 10); and ii. the set of odd constants (e.g. 11, 013, and Oxd are three such constants, all have an odd value of 11). For each set, give three regular expressions for the three constant forms. (There should be a total of six regular expressions.) You should use conventional regular expression notations, as shown in class (Week 2 slides). Python RegEx's special sequences are not allowed. (Hint: Be careful with zeros. Which constant form does each of the following literals represent, 0, 00, and 000?) (c) [2] The above two sets are defined with a reference to integer values (i.e. even vs odd), which is not exactly a syntax term. Do you think it's coincidental that you are able to define regular expressions for those sets based on a value-oriented specification? Or do you think it can be generalized to other sets defined with a value reference? Provide a convincing argument; use examples if necessary.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started