Computer Science 301 - Translators


Tutorial 4 - Regular Expressions and Cocol Grammars

(a) Develop a regular expression and/or a Cocol token definition that describes identifiers of the sort used in many programming languages, subject to the restriction that underscores may not appear at the start or end of an identifier. but may appear in the interior of an identifier.

(b) Develop a regular expression and/or a Cocol description that describes comments of the form allowed in the C family of languages.

Hint: Here are some examples of strings that might be valid comments. One of them, however, cannot be a comment. Which is it? Can your Regular Expression accommodate the valid ones?

     (1)   /* comment */
     (2)   /* multiply a * b */
     (3)   /* divide a / b */
     (4)   /* ***** */
     (5)   /*********/
     (6)   /* ** /* // */
     (7)   /* // */ ** */
     (8)   /*a*b*/
     (9)   /* **a/b* ** */

(c) Develop a Cocol grammar to describe a list of names of some well loved (well, well respected) folk who have titles, first names and/or initials, surnames, and (usually) qualifications - for example

          Professor P.D. Terry, MSc, PhD .
          George Clifford Wells, BSc(Hons), MSc, PhD .
          C. Hubert H. Parry, BMus.
          Greg G. Foster, PhD .
          Dave A. Sewry, PhD .
          Dr Karen Lee Bradshaw, MSc, PhD .
          Caro Watkins, BSc .
          Professor Richard J. Foss, PhD.
          Your Name One Day, BSc(InfSys), PhD .
          Mx Mic Halse .
          Madonna .
          Dr Mabizela .


Home  © P.D. Terry