Programming Languages and Translators
Homework Assignment #1
Submit solutions in pdf format on
by 2:40pm, March 3, 2014
- You may discuss the questions with others but your answers
must be your own words and your own code.
- Problems 1-5 are each worth 20 points.
- Solutions to these problems will be posted
on Courseworks on March 5, 2014.
- This assignment may submitted electronically on Courseworks by 2:40pm,
March 5, 2014 for 50% credit.
- Be sure to put your name and uni on your answers.
- In at most two sentences explain the difference between
- a compiler and an interpreter
- a functional language and an object-oriented language
- a statically typed language and a dynamically typed language
- a lexeme and a token
- top-down parsing and bottom-up parsing
- 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
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
You can use any variant of Lex such as Flex, JLex, Ocamllex, PLY, etc.
Mention which version of Lex you used.
- Let R be the regular expression
- Describe in English L(R), the language denoted by this regular expression.
- Construct N, the McNaughton-Yamada-Thompson NFA, from R.
- 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.
- Convert N into a deterministic finite automaton D.
- Minimize the number of states in D.
- Interactive desk calculator for boolean nand-expressions.
- Consider the boolean operator
Construct the truth table for
- Construct an unambiguous context-free grammar that generates boolean nand-expressions
containing the logical
left-associative binary boolean operator
nand, and parentheses.
- Show the parse tree according to your grammar for the nand-expression
true nand true nand (false nand false).
- Using Lex and Yacc or their equivalents, implement an interpreter that evaluates newline-terminated
input lines of boolean nand-expressions generated by your grammar
Show the Lex-Yacc code for your calculator.
- What output does your calculator generate for the nand-expression
true nand true nand (false nand false)?
- Let L be the language generated by the grammar
S → a S b S | ε.
- 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.
- Using the pumping lemma for regular languages prove that L
cannot be specified by a regular expression.