 Interactive desk calculator for boolean norexpressions.
 Construct a grammar that generates
boolean norexpressions
containing the logical
constants
true
and false
, the
leftassociative binary boolean operator
nor
[where p nor q
means not (p or q)], and
parentheses.
 Show the parse tree according to your grammar for the norexpression

true nor true nor (false nor false)
 Implement an interpreter that takes as input newlineterminated
lines of boolean norexpressions and produces as
output the truth value of each expression.
You can use lex and yacc or their equivalents
to implement your interpreter. Show the source
code for your interpreter and the sequences of
commands you used to test it.
 Run your interpreter on the following two inputs and show the outputs:
 (a)
(true nor false) nor (true nor false)
 (b)
true nor true nor (false nor false)
 Infix to stack machine code translator
 Consider the Yacc specification in Fig. 4.59 of ALSU (p. 292).
Modify this translator to produce stack machine code for
each input line. For example, for the input "1*(2+3)" your translator
should produce the instructions
push 1
push 2
push 3
add
multiply
done
 Implement your translator in Yacc (or its equivalent) and show the
stack machine code generated for each of the following inputs:
 (i)
1+2*3
 (ii)
1+(23)
 (iii)
1+2+3
 (iv)
1+23
 Let L be the language generated by the following grammar:
S → a S b S  b S a S  ε
 What language does this grammar generate?
 Show that this grammar is ambiguous.
 Construct the predictive parsing table for this grammar.
 Construct an LL(1) grammar for L.
 Construct the predictive parsing table for your grammar.
 Let L be the language of pure lambda calculus
expressions generated by the following grammar:
E → ^ v . E  E E  ( E )  v
 The symbols
^, ., (, )
and v
are tokens.
^
represents lambda and
v
represents a variable. 
 An expression of the form
^v.E
is a function definition
where v
is the formal parameter of the function and
E
is its body.
 If f and g are lambda expressions, then the lambda
expression fg represents the application of the function f
to the argument g.
 Show that this grammar is ambiguous.
 Construct an unambiguous grammar for L assuming that
function application is left associative, e.g., fgh = (fg)h,
and that function application binds tighter than
.
,
e.g., (^x.
^y.
xy)
^z.
z =
(^x. (^y. xy)) ^z.z.
 Using your grammar, construct a parse tree for the expression
(^x
.
^y.
xy) ^z.
z.
 Using the command
yacc v
on a file containing your grammar,
show the LALR(1) parsing action and goto table for your grammar.
aho@cs.columbia.edu