In: Computer Science
Give regular expressions for
(c) C indentifiers
(d) Binary strings consisting of either an odd number of 1s or an odd number of 0s
Identifers are the names given to variables, functions, arrays, unions, structures, strings and user-defined data.
Identifiers are the names which are given to the programming elements used for identification purpose.
There are some rules for naming identifiers in C programming language.
Example:
int xyz;
int class1;
here xyz, class1 are identifiers.
c) The regular expression for C identifiers is
[A-Za-z_][A-Za-z0-9_]*{0,30}
The first charecter is a letter or underscore followed by zero or more charecters.
In above regular expression,
[A-Za-z_] specifies the first charecter of the identifier starts with the alphabet or underscore(_).
A-Z: Uppercase alphabets A, B, C, ... , Z
a-z: Lowercase alphabets a, b, c, ... , z
_ : Underscore
[A-Za-z0-9_]* specifies the character of identifiers with the alphabets or numbers or _
* specifies occurance zero or more times of (A_Za-z0-9_].
{ } Used to limit the length .
d) Regular expression for binary strings consisting of either an odd number of 1s or an odd number of 0s
The alphabet = {0,1}.