Question

In: Computer Science

Write the RE for identifiers that can consist of any sequence of letters (l) or digit...

Write the RE for identifiers that can consist of any sequence of letters (l) or digit (d) or "_" but the first char must be a letter and the last char cannot be a "_"

Solutions

Expert Solution

So, as given in the question, we need to write a Regular Expression (RE), which consists of any sequence of letters (we represent letters as 'l'), or any sequence of digits (we represent digits as 'd'), or the particular symbol '_'. Here a condition is given that is, the first char or symbol must be a letter, which means must be 'l', and not any digit 'd' or symbol '_'. Also, the last char or symbol can not be the symbol '_'.

So, what can our language be? Let us first see the language with examples -

Language (L) can be {l, ld, ll, l_d, l_l, lll, ldd, l_d_d, ...} (can go infinitely)

(Very Important) Here it is stated that the start symbol or char will be the letter 'l', and the last char can not be '_', so last char can be 'l', and in between, you may have any sequence of letters means you may have a sequence of 0 length too, so only 'l' will be there in the language. A word from our language set L, 'ld', start with 'l', end with 'd', which is valid, and in 'l_d', it starts with 'l', the middle is a single sequence of the symbol '_' and then end in digit 'd'. With this, we are creating the language but 'd' can not be in language, because it does not start with 'l'.

Also, I will tell you a little bit about Kleen star (represented as '*'), which means making the set of all possible strings from a finite length of alphabet or symbol given. You can also rephrase it as you can construct strings of any length or sequence from a given set of symbols (which is here {'l', 'd', '_'}). It can also be a null string or strings with a length of 0, which we call as epsilon (represented as ).

Ex - a* = {, a, aa, aaa, aaaa, ....} (where 'a' is our symbol)

Suppose we have some symbol set {a, b}, and we have RE as (a + b), then the language set contains {a, b}, means EITHER 'a' OR 'b', & if we have RE as (a . b), then the language set contains {ab}, means 'a' AND 'b'. Just like logic gates, + is OR and . (dot) is represented as AND.

Now that we know what our language is, and we have a good idea about Kleen star, & other RE operators, so let us make the RE for the abovementioned language. So, our RE will be =

l . (l + d + _)* . (l + d)

or

letters . (letters + digits + _)* . (letters + digits)

Although I have told you how to write it indirectly, let me explain to you again, what this exactly means. So, here in our RE, the language starts with 'l', then we have 'l . (l + d + _)*', and it means l AND (l OR d OR _)*, where

(l + d + _)* = {, l ,d, _, ld, dl, l_, d_, _d, _l, ll, dd, ___, lll, ___, ddd, ldl, l_d, d_l, ... } (as I told, any possible sequence of string starting from length 0 to infinity). So, 'l . (l + d + _)*' = {l, ll, ld, l_, l_l, l_d, ld_, ...}, but this can end in '_', so this can not be the end of our RE.

In (l + d), we can have either 'l' or 'd', but can not have both, so by this we can not have the last char as '_'.

Hope you got it now. Thank you.


Related Solutions

Write the RE for identifiers that can consist of any sequence of letters (l) or digit...
Write the RE for identifiers that can consist of any sequence of letters (l) or digit (d) or "_" but the first char must be a letter and the last char cannot be a "_" (10)
Describe the rules governing identifiers. Can identifiers be re-used in the same Java class file? Provide...
Describe the rules governing identifiers. Can identifiers be re-used in the same Java class file? Provide three examples of different kinds of invalid identifiers. Java
1An identification code is to consist of 2 letters followed by 5 digit. Determine the fallowing?...
1An identification code is to consist of 2 letters followed by 5 digit. Determine the fallowing? 1a) how many different codes are posible if repetition is permitted? 1b) how many different codes are possible if repetition is not permitted, but the first 2 letters must ve the same letter? 1c) how many different codes are possible if the first letter must be, P, Q, R, S, T, and repetition for everything else is not permitted?
Write a regular expression that can represent any digit, without more than one digit or non...
Write a regular expression that can represent any digit, without more than one digit or non digit characters.
write a program that uses exactly four for loops to print the sequence of letters below...
write a program that uses exactly four for loops to print the sequence of letters below A A A A A A A A A A B B B B B B B C C C C C C E E E E E
How many: New York license plates can be made that consist of 3 letters followed by...
How many: New York license plates can be made that consist of 3 letters followed by 4 numbers given the restriction that if the first letter is an ‘N’, then the second letter must be a ‘Y’? New York license plates can be made that consist of 3 letters followed by 4 numbers given the restrictions that (1) if the first letter is an ‘N’, then the second letter must be a ‘Y’ and (2) if the second letter is...
The user enters some text into a textbox. It can contain any characters (letters, digits, spaces,...
The user enters some text into a textbox. It can contain any characters (letters, digits, spaces, punctuation marks, and there is no length limit). When a button Count is hit , display the number of upper-case letters in the inputted phrase. This must be done in visual studios using C#.
How can I re-write the following questions as closed-ended questions to be included in a questionnaire?...
How can I re-write the following questions as closed-ended questions to be included in a questionnaire? 1. Do agree that the World Bank were able to measure the degree to which loan conditions were implemented in Emerging Markets when political influences favored policy reforms during the fall-out of the 2008 Global Economic Crisis. 2. In response to the 2008 Global Economic Crisis, do agree that the World bank efficiently reduced poverty by increasing lending in larger degrees to middle income...
I am completing a questionnaire for my course. How can I re-write following questions as closed-ended...
I am completing a questionnaire for my course. How can I re-write following questions as closed-ended questions to be included in the questionnaire? 1.Do you believe that World Bank loans significantly helped economic development in Emerging Markets during 2008-2016. 2. Please indicate the extent to which you agree with the following statements: a) The World Bank helped improve the enabling environment for SME firms in Emerging Markets during 2008-2016. b) The World Bank’s mainstreaming of framework agreements addressed project implementation...
Programming. Write only code for the following. Do not write any comments. You can submit your...
Programming. Write only code for the following. Do not write any comments. You can submit your answer as .java file(s). #1. Design a Java JProduct class for a product which implements both cloneable and comparable interfaces The class should have the following private member variables: m_id: an integer that holds the product ID m_name: a string that holds the product name m_wholesaleprice: a double that holds the wholesale price m_retailers: a String array that holds all retailers who sell the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT