in Theory of Computation
1,063 views
0 votes
0 votes

Let L be the set of letters {_,A,B,...Z,a,b,…z} and D be the set of digits {0,1…9}. Then which of the following regular expression represents the set of valid C identifiers. Assume that any C keyword is also allowed as variable name.

  1.  L*(L+D)*
  2.  LL*D*
  3.  L(L+D)*
  4.   None of the above

Please explain with valid reason..?

Thanks,

in Theory of Computation
1.1k views

1 Answer

2 votes
2 votes

In this question the premise assumes that we are only talking about identifier construction with digits and letter as given in form of two sets , D and L.

The regular expression is:= L(L+D)* because the first character in naming an identifier should be a letter then it can be followed by any digit or letter.

Hence the answer is C.

I am providing a snapshot which gives a similar regular expression for C identifier construction:

by