






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







(ualbb)’
(ablba)
(^) generated
£
),
(^) 2.;
EJo
•Qii)aaab
(^) io
Wa
Ia^
cc;
B
B
L—a
#^
#^
#^
#^
Ccc’c{r^
OCt
34ccvLpcortcJ
QSQtiftt)U
vet,(
1
(iv)
that (^) we wanted
(^) to add
(^) a unary operator
with (^) lower
precedence
than #.
Add parentheses
to the following
expression
to show (^) how (^) it would
giver
these precedences
7a#b)
)
(v) Modify
the original
grammar
(^) so that (^) it (^) is not ambiguous
(^) making
(^) the fewest
changes
to rules (^) possible
r. r
c o
) )
-‘ t- L
and LR Grammars.
Consider
the
(^) ri-else
and E
hand (^) a
::= iLtSeS
iEtS
(
(i)•^ Rewrite
to eliminate
(^) the common
(^) prefix (^) in the first two productions
for
j
(
ci /
c’)
$,r I^
Km -
C
(ii) Construct
(^) the LL(1) parsing
(^) table (^) for the (^) grammar
from (^) (i). (^) Show
your FIRST
and
(^) for relevant
(^) sequences
(^) of
r-—--—-
.
L
.-
t.
-r----—
c: iZ
JEizJz
ZiL
(iii) This (^) grammar
(^) is not (^) LL(i).
(^) Is (^) it possible to
(^) resolve
the (^) conflict(s)
such (^) a way
that the^ LL(1) parser (^) will parse Jthen-else
statements
(^) normally
(^) (i.e., (^) an (^) else
he
then)?^
your (^) answer.
jC
.
.
.
L
r
L
the^ (^) CFSM
(^) for the (^) original
(^) Make (^) sure that (^) von (^) show (^) each (^) state.
fill
items (^) in the (^) state, (^) label (^) all transitions,
(^) and (^) write (^) the (^) necessary
(^) “Reduce
(^) by.
labels
states.
;‘eL
!——---t
L f’tU
e
L-’—’. 4
::-
c
a ‘‘‘l
---t
r tThj
conflict
(^) (i.e..
r,
ub
.‘
1 % Ii, t a
a
1
__-—
r “‘‘
,
‘b__i
1 zzL:;
—; !
ah
a
%r
token fr
F
L
F L.
I
I.
SV
I” S
,,‘t 1 Ht
—Id
Id
, r
a
, .
I’
N
; :
.
1:
C-
5
IA-t_
(^) Icl+U
l’a
wes.
—
—
(^) —
(^) *
I
I
‘IS
J
;J.
e ko-s
ts”’
r
(^) f4Rk
4
4- i
(^) ensure
reckiareduce).
Prolog
P1. Given
the (^) following
Prolog
clauses
(^) defining
predicate
()f^ (^) , answer
the questions
below.
The (^) built-in
predicate
integer()
returns (^) true (^) when its^ argument
(^) is an integer (^) or
avariable bound
(^) to an integer
value, else (^) fails. The (^) built-in
predicate
var() (^) returns
(^) true
when (^) its argument
(^) is an unbound
(^) variable,
else (^) fails.
f([ ],o).
f([jY],L)
0, M is L-1,
f(Y,M),
is M÷1.
f([Y),L)
var(L),
f(Y,M),
is M+1.
Write what^ answer
(^) is returned
(^) by the (^) following
queries
(notice (^) we are (^) looking
(^) for the
first answer (^) only):
f([1,2,3),x).
ii.?-
f([1,2,3],4).
iii.
?- f(X,3).
f(X,Y).
v. Describe
(^) briefly (^) (1- sentences)
(^) what the (^) fpredicate
(^) calculates.
Practice
(^) Problems
(part 2>
Scoping
The interesting
thing about this language
isthat procedures
whose names
are in upper-case
use (^) dynamic
scoping
to lookup non-local
variables,
whereas procedures
whose
names
are in
lower-case
use lexical
scoping
to lookup
non-local
variables.
You will trace the execution
of
this program and
answer
the following
(^2) questions:
(i) What isthe output ofthis (^) program?
procedure main
main
0
icaI-liixx
{
:= 0;
// all (^) initially
0
dynamic-link
xxxx
{
:=
C;
if (b mod 2 =
then
QO;
else
p () ;
procedure
“#2”,
a, b, c;
lexical-link
}- - end p;
dynamic-link
procedure
Q()
{
:= 0;
C++;
“#3”,
a, (^) b,
c;/****/
}- -end
Q;
lexical-linkprocedure
n
“#4”,
a, b, C;
dynamic-link
(ii) Show (^) the (^) run-time
stack when execution^
reaches
/***/ using (^) the (^) frames
at the right. (^) You may not need to use all the (^) frames.
procedure
U\
dynamic-linklexical-link
I
)
lexical-linkprocedure
lv
dynamic-link