Programming Assignment 1, Advanced Programming I

Advanced Programming I, Spring 2007

Programming Assignment 1 - An Example Solution


Table of Contents

Introduction

This page presents an example solution to the first programming assignment. The assignment requires a program that repeatedly reads in a regular expression re, generates the strings in the language associated with re, and writes the strings to std-out. This solution would work if the data types regular_expression and language and the procedures input_regexp(), generate(), and output_language() were defined, but, alas, they aren't. It is usually better to define the procedures first, then the data structures. The data structures are simpler than the procedures, and working through the procedure definitions provides helpful information about what the data structures should be able to do.

To generate the regular language associated with the option regular expression ? regexp, just generate the regular language associated with regexp and add the empty string to represent what happens when the option isn't taken. For example, ? a generates {"a", ""}. To generate the regular language associated with the choice regular expression | regexp1 regexp2, take the union of the regular languages associated with regexp1 and regexp2. For example, | a b generates {"a", "b"}.

Main

Generating Regular Languages

Regular Expressions

Languages

A language is a set of strings, which is almost a list of strings except for duplicate strings, which should be suppressed in a set.

String Lists

Index


This page last modified on 1 March 2006.