Question

In: Computer Science

Give regular expressions for (c) C indentifiers (d) Binary strings consisting of either an odd number...

Give regular expressions for

(c) C indentifiers

(d) Binary strings consisting of either an odd number of 1s or an odd number of 0s

Solutions

Expert Solution

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.

  • The Valid identifiers can be combination of uppercase alphabets, lowercase alphabiths, digits, special charactes, and underscore. (a-z, A-Z, 0-9, _, etc., )
  • The first letter of identifier should be either a letter or underscore(_), but not a digit.
  • The maximum length of the identifier is <=31 in C programming language.
  • We can not use Keywords( INT, CHAR, FLOAT, etc.,) as identifiers.
  • Blank spaces are not allowed in names of identifiers.

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}.


Related Solutions

Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
1. Write a Post system that defines the set of binary strings of odd length that...
1. Write a Post system that defines the set of binary strings of odd length that have a “x” as the middle character and "x" is a string
Consider a system which has to accept prefix arithmetic expressions consisting of ‘+’(binary addition) , ‘-‘(binary...
Consider a system which has to accept prefix arithmetic expressions consisting of ‘+’(binary addition) , ‘-‘(binary subtraction), ‘*’(multiplication), ‘~’(unary subtraction), single digit numbers and compute their value. Examples: +12 → 3 ++12 → fail +*123 → 5 *+123 → 9 +123 → fail What parts would be required for such a system? How do these parts relate to the concepts studied? Could you write a program to implement such a system? (Layout of the structure and the logic of the...
Regular => Context-Free Give a proof by induction on regular expressions that: For any language A,...
Regular => Context-Free Give a proof by induction on regular expressions that: For any language A, if A is regular, then A is also context-free. You may assume that the statements from the previous Closure under Context-Free Languages problem are proved. R is a regular expression if RR is: a for some a∈alphabet Σ, the empty string ε, the empty set ∅, R​1​​∪R​2​​, sometimes written R​1​​∣R​2​​, where R​1​​ and R​2​​ are regular expressions, R​1​​∘R​2​​, sometimes written R​1​​R​2​​, where R​1​​ and...
5 Regular => Context-Free Give a proof by induction on regular expressions that: For any language...
5 Regular => Context-Free Give a proof by induction on regular expressions that: For any language A, if A is regular, then A is also context-free. You may assume that the statements from the previous Closure under Context-Free Languages problem are proved.
Write a c++ program to convert any decimal number to either binary base  or Hex base...
Write a c++ program to convert any decimal number to either binary base  or Hex base number system. Test your program with the followings: Convert 15 from decimal to binary.  Convert 255 from decimal to binary. Convert BAC4 from hexadecimal to binary Convert DEED from hexadecimal to binary.  Convert 311 from decimal to hexadecimal. Convert your age to hexadecimal.
Design an efficient algorithm to compute the number of binary strings with length n that satisfy...
Design an efficient algorithm to compute the number of binary strings with length n that satisfy 1 the regular expression ((0 + 11 + 101)∗ (1101))∗ .
Find a recurrence relation for the number of binary strings of length n which do not...
Find a recurrence relation for the number of binary strings of length n which do not contain the substring 010
Use inclusion-exclusion to find the number of binary strings of length 5 that have at least...
Use inclusion-exclusion to find the number of binary strings of length 5 that have at least one of the following characteristics: start with a 1, end with a 0, or contain exactly two
Create and test a python regular expression that matches a street address consisting of a number...
Create and test a python regular expression that matches a street address consisting of a number with one or more digits followed by two words of one or more characters each. The tokens should be separated by one space each, as in 123 Main Street.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT