CS 454, Section 001 Sonoma State University Spring, 2024
 
Theory of Computation
Instructor: Henry M. Walker

Lecturer, Sonoma State University
Professor Emeritus of Computer Science and Mathematics, Grinnell College

Although much of this course has been well developed in recent semesters, the SSU CS faculty recently have approved an updated course description. Also, the required SSU Signature Project for SSU's Upper Division GE Area B Requirement for CS Majors has been rethought for this course. Currently, the Web site is reasonably stable, but modest refinements are likely. Check these pages regularly for adjustments.


Contract Negotiations Have Yielded a Tentative Agreement

Since May, 2024, the California Faculty Association (CFA) – the labor union of professors, lecturers, librarians, counselors, and coaches across the 23 California State University campuses – has been in negotiations with the management of the California State University System. After a one-day strike on Monday, January 22, the two sides have reached a tentative agreement, and the strike has been called off. Effective Tuesday, January 23, SSU classes (including CS 454) will be held as scheduled.

Assignment on Context-Free Languages

  1. Unions and Intersections of Context Free Languages:

    1. Give a short, simple argument to prove that the union of two context free languages is also a context free language.
    2. Show that the language {0m 1n 0m | m and n are non-negative integers} is context free. (Hint: produce a grammar.)
    3. Show that the language {0m 1m 0n | m and n are non-negative integers} is context free. (Hint: produce a grammar.)
    4. Show that the intersection of the languages for parts b and c is not a context free language. (Note that this example shows that the intersection of context free languages need not be a context free language.) (Hint: this is easy if you have studied the book.)
  2. Strings with complementary numbers of a's, b's, and a's: Working with the alphabet Σ = {a, b}, consider the language M that contains all strings over Σ of the form anbnan, where n is any non-negative integer.

    Determine whether or not M is a context-free language.

  3. Strings with twice the number of a's than b's: Working with the alphabet Σ = {a, b}, consider the language L that contains all strings over Σ for which the number of a's is exactly twice the number of b's .

    Determine whether or not L is a context-free language.

  4. Optional, for Extra Credit: Context-free Grammars, Programming Languages, and Compilers: For many [most? all?] modern programming languages, the parsing of a program depends upon the specification of the language though a context-free grammar. For example, considerable time and effort is allocated in CS 452, Compiler Design and Construction, to parsing techniques that typically are based on context-free grammars. However, such parsing techniques are beyond the scope of CS 454. (That is, CS 452 already covers this material, and coverage of parsing in CS 454 would prevent coverage of other topics related to the Theory of Computation). As a partial substitute, this exercise may provide some historical context and insight regarding the use of context-free grammers in specifying a programming language.

    For the purposes of this exercise we focus on a small part of an overall programming language: accessing an element within an array. For example, if arr has been declared as an array, a simple access to element 5 might have the following form:

    (Here, FORTRAN uses round parentheses for array indices, whereas several other languages us square brackets, but the idea of an array is quite similar.)

    In what follows, for consistency in specification alphabets, arithmetic expressions may include all one-digit integers, as well as two integer variables, a and b.

    Two basic question for this exercise are, "what expressions are allowed for an array subscript", and "how should an expression be evaluated"? Three different specifications might be considered:

    1. In 1966, FORTRAN was the second programming language to be standardized (the first language was COBOL in 1960.) In particular, Section 5.1.3.2 of the FORTRAN 66 standard specifies possible options for array subscripts,

      Notes:

      • This early version of FORTRAN was standardized before context-free grammars were used in specifying programming languages. Reports I have heard suggest that limitations on array subscripts were included in FORTRAN 66 to limit the complexity of compliers.
      • For those interested, FORTRAN is reported to stand for "Formula Translation", whereas COBOL is an acronym for "Common Business Oriented Language".
      • Historically, FORTRAN and COBOL developed for different audiences: scientific applications and business.
    2. Example 2.4 in both Sipser's Second Edition and Sipser's Third Edition provides a context free grammar for arithmetic expressions that is somewhat simplified from the grammar used in C/C++. For this exercise, expand the grammar to allow one-digit integers and both variable a and b in expressions.

    3. The following grammar is another, simple grammar for arithmetic expressions over the same alphabet used in Example 2.4.

      <expr> → <expr> + <expr> | <expr> - <expr>
      | <expr> * <expr> | <expr> / <expr>
      | ( <expr> ) | a | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

    Exercise: For each of these specifications, consider each of the following expressions, and determine if the expression is a valid array subscript according to the specification.

    Expressions (where * is used for the multiplication operator):

    1. 2*a + 3*a
    2. 5 + 7*a
    3. 2*(a + 1)*3
created Fall, 2023
revised Fall, 2023
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.