COMS W4115
Programming Languages and Translators
Homework Assignment #1
Submit solutions in pdf format on
     by 2:40pm, March 3, 2014



  1. In at most two sentences explain the difference between
    1. a compiler and an interpreter
    2. a functional language and an object-oriented language
    3. a statically typed language and a dynamically typed language
    4. a lexeme and a token
    5. top-down parsing and bottom-up parsing

  2. Construct a Lex program to find the lexicographically first longest word in the dictionary that can be made up using only the lowercase letters associated with the last four digits in your telephone number. E.g., on a telephone dial pad, the letters a,b,c are associated with the digit 2, the letters d,e,f with the digit 3, and so on to w,x,y,z with the digit 9. As part of your answer print your Lex program, show the last four digits of your telephone number, and print the longest word that was found. State what dictionary you used (e.g., on Linux systems /usr/dict/words). You can use any variant of Lex such as Flex, JLex, Ocamllex, PLY, etc. Mention which version of Lex you used.

  3. Let R be the regular expression a(a|b)*b.
    1. Describe in English L(R), the language denoted by this regular expression.
    2. Construct N, the McNaughton-Yamada-Thompson NFA, from R.
    3. Show how the two-stack algorithm would process the input string abaab. Just show the sequence of stack contents at the beginning and after reading each input character.
    4. Convert N into a deterministic finite automaton D.
    5. Minimize the number of states in D.

  4. Interactive desk calculator for boolean nand-expressions.
    1. Consider the boolean operator nand where p nand q means not (p and q). Construct the truth table for p nand q.
    2. Construct an unambiguous context-free grammar that generates boolean nand-expressions containing the logical constants true and false, the left-associative binary boolean operator nand, and parentheses.
    3. Show the parse tree according to your grammar for the nand-expression  true nand true nand (false nand false).
    4. Using Lex and Yacc or their equivalents, implement an interpreter that evaluates newline-terminated input lines of boolean nand-expressions generated by your grammar to either true or false. Show the Lex-Yacc code for your calculator.
    5. What output does your calculator generate for the nand-expression  true nand true nand (false nand false)?

  5. Let L be the language generated by the grammar Sa S b S | ε.
    1. Describe L in English. E.g., L is the set of all strings of a's and b's such that . . . Using induction prove that your answer is correct.
    2. Using the pumping lemma for regular languages prove that L cannot be specified by a regular expression.