Question 5 Calculate the free variables of the following expressions:1. x + (fn y : int ⇒ z)2. (fn y : int ⇒ (fn y : int ⇒ (fn y : int ⇒ y)))3. while !l0 ≥ y do l0 := xDraw also their abstract syntax trees (up to alpha equivalence)
Question
Question 5 Calculate the free variables of the following expressions:1. x + (fn y : int ⇒ z)2. (fn y : int ⇒ (fn y : int ⇒ (fn y : int ⇒ y)))3. while !l0 ≥ y do l0 := xDraw also their abstract syntax trees (up to alpha equivalence)
Solution
x + (fn y : int ⇒ z)
The free variables in this expression are x and z. The variable y is bound by the function abstraction fn y : int ⇒ z.
Abstract Syntax Tree (AST):
+
/ \
x fn y : int ⇒ z
\
z
(fn y : int ⇒ (fn y : int ⇒ (fn y : int ⇒ y)))
There are no free variables in this expression. All occurrences of y are bound by their nearest enclosing function abstractions.
Abstract Syntax Tree (AST):
fn y : int ⇒
\
fn y : int ⇒
\
fn y : int ⇒
\
y
while !l0 ≥ y do l0 := x
The free variables in this expression are l0, y, and x.
Abstract Syntax Tree (AST):
while
/ \
!l0 ≥ y
\
l0 := x
/ \
l0 x
Note: In the ASTs, each node represents an operator or a variable, and each edge represents an operand relationship. The root of the tree is the main (outermost) operator of the expression. The leaves are the variables or constants.
Similar Questions
Question 6 Perform the following substitutions:1. {y z/x} (fn x : int ⇒ y x)2. {z x/x} (fn y : int ⇒ y x)3. {z x/x} (fn z : int ⇒ (fn x : int ⇒ y x) x z)
10. Which of the following programming structures does not logically agree with the others?a) m=n>r<x;b) m=n!=x;c) m=n*x;d) m=n>=x
Which one of the following statements is FALSE?Question 7Answera.High-level language programs can be translated to different Intermediate Representations.b.Arguments to a function can be passed using the program stackc.Type checking is done before parsingd.Context-free grammar can be used to specify both lexical and syntax rules.Clear my choice
1) Composition of functions2) Monoid3) Existential Quantifier4) Partially Ordered Set5) Boolean Algebra6) Tree7) Complete Graph
A C program contains the following variable declarations.f l o a t a = 2.5, b = 0.0005, c = 3000.;Show the output resulting from each of the following p r i n t f statements.(a) p r i n t f ( " % f %f%f",a, b, c ) ;(b) p r i n t f ( ' % 3 f %3f % 3 f n , a, b, c ) ;(c) p r i n t f ( " 8 f %8f % 8 f " , a, b, c ) ;(d) p r i n t f ( " % 8 . 4 f %8.4f %8.4fn, a, b, c ) ;( e ) p r i n t f ( I 1 % 8 . 3 f %8.3f %8.3f1', a, b, c ) ;cf) p r i n t f ( " % e %e %e", a, b, c ) ;(g) p r i n t f ( " % 3 e %3e %3e", a, b, c ) ;(h) p r i n t f ( " % l 2 e %12e %12e', a, b, c ) ;( i ) p r i n t f ( " % l 2 . 4 e %12.4e %12.4en, a, b, c ) ;(j) p r i n t f ( " % 8 . 2 e %8.2e %8.2e", a, b, c ) ;( k ) printf("%-8f %-8f %-8f", a, b, c ) ;(0 p r i n t f ( " % + 8 f %+8f %+€If", a, b, c ) ;(m) p r i n t f ( " % O 8 f % O a f % O a f n , a, b, c ) ;(n) p r i n t f ( " % # 8 f %#8f % # 8 f " , a, b, c ) ;(0) p r i n t f ( " % g %g %g", a, b, c ) ;(p) p r i n t f ( " % # g %#g %#g", a, b, c ) ;4.80 A C program contains the following variable declarations.char c l = ' A ' , c2 = " B ' , c3 = ' C ' ;Show the output resulting from each of the following p r i n t f statements.(a) p r i n t f ( * % c %c %c", c l , c2, c3);( 6 ) p r i n t f ( " % c % c % c " ,c l , c2, c3);(c) p r i n t f ("%3c %3c %3c" c l , c2, c3) ;(6) printf("%3c%3c%3cW,c l , c2, c3);( e ) p r i n t f ( "cl=%c c2=%c c3=%cW,c l , c2, c3) ;4.81 A C program contains the following statements.#include <stdio.h>char t e x t [ 801 ;Write a p r i n t f function that will allow the contents of t e x t to be displayed in the following ways.(a) Entirely on one line.(b) Only the first eight characters.(c) The first eight characters, preceded by five blanks.(d) The first eight characters, followed by five blanks.4.82 A C program contains the following array declaration.char t e x t [ 8 0 ] ;Suppose that the following string has been assigned to t e x t .
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.