You are on page 1of 2

Assignment 1

Programming Language Concepts (CS 421/521) Section 2, Fall 2014


Due: Friday, September 19th
5 problems worth 5 points each. Submit your solutions, as a single PDF le, to the dropbox on
D2L. See the Assignment Guidelines handout for the grading rubric and related information.
Problem 1.
Give regular expressions for the following languages.
(a) All strings that are valid Java identiers.
(b) All strings over = {a, b, c} such that the number of characters that are not c is odd.
(c) All strings over = {a, b, c} such that no a occurs after a c.
Problem 2.
Give a FSM whose language is the set of all strings over = {a, b, c} such that no a occurs after a
c. Show a run of your FSM on input
1
= abacb and
2
= abacba .
Problem 3.
For numbers in bases of the form base#number# (without embedded whitespace) give:
(a) a regular expression
(b) a FSM
(c) a portion of a lexer which handles arbitrary sequences of integers, oating point numbers,
and numbers of the form base#number# .
The base should be expressed in decimal, and the number should use lower case letters to represent
digits greater than 9. Note that you only need to handle bases of up to 16 (hexadecimal) and you
dont need to ensure consistency with respect to the base, e.g., #8#99 can be allowed by your
grammar even though it is illegal.
Problem 4.
Give a CFG for Boolean expressions in Java that have only the literal values true and false as
operands and the operators &&, ||, and !. Remember that ! has the highest precedence, && has the
next highest precedence, and || has the lowest precedence. Also, ! has right-to-left associativity,
and both && and || have left-to-right associativity.
Problem 5.
Part 1: Argue convingly that the following grammar which denes the language of arithmetic
expressions having the operators + and and one digit operands is ambiguous.
Expr Expr + Expr | Expr Expr | Term
Term 0 | . . . | 9 | (Expr)
Part 2: Argue convingly that the following grammar which denes the language of arithmetic
expressions having the operators + and and one digit operands is unambiguous.
Expr Expr + Term | Expr Term | Term
Term 0 | . . . | 9 | (Expr)

You might also like