Section notes: Week 4

CS 164, Fall 2005

Class Exercises

What's wrong with the following regular expressions?

Consider a language which includes the keywords if, then, in, the, and is.

Consider the regular expression (0 | 1 (0 1* 0)* 1)*.

We've seen how to process a string character-by-character in order to produce a Lisp integer. What about more interesting numeric tokens?

Nickle rational numbers can be written as int.fixed{repeat}. For example, the fraction 4/3 would be written as 1.{3}. The integer part is not optional, so 1/3 is written 0.{3}, not .{3}.

If you ask a calculator to show a rational number, it will print only a finite number of digits; typically, you would round in the last digit, so that 0.{6} might display as 0.66667. You could also chop in the last digit, just discarding the rest of the number, so that 0.{6} would display as 0.66666.

Extra Exercises

You have probably seen this old trick for testing whether an integer is a multiple of 3: if the sum of the digits is a multiple of 3, then so is the integer. You can use a similar trick to recognize repeating decimals of the form p/11 (how?).

I pose these left-over questions as challenges. We probably won't get to these questions, but I pose them as challenges. Come explain an answer to one to me in office hours to get out of a quiz next week.

Question for next time

What's the muddiest point for you so far in the course?