Assignment 1

1.1

Describe the languages denoted by the following regular expressions:

  1. 0(0|1)*0
  2. (0|1)*0(0|1)(0|1)
  3. 0*10*10*10*
1.2

Write regular definitions for the following languages.

  1. Floating-point numbers. A floating-point number has the following parts: an integer, a decimal point (.), a fractional part, and an exponent. The exponent, if present, is indicated by the ASCII letter e or E followed by an optionally signed integer.
  2. Binary strings with even number of 1s.
  3. All strings of letters in which the letters are in ascending lexicographic order.
  4. Comments consisting of a string surrounded by /* and */ without an intervening */ unless it appears inside the quotes " and ".
1.3

Write a function in C or Java to recognize identifiers and integers as defined in the following:

Letter -> [a-z] | [A-Z]
Digit -> [0-9]
NonzeroDigit -> [1-9]
Identifier -> Letter (Letter | Digit)*
Integer -> 0 | NonzeroDigit (Digit)*

Your function should take a string and return 0 if the string is an integer; 1 if an identifier; and 2 otherwise.