Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

1. Consider the following attributed tree grammar for type checking a program AST. For simplicity, it hard codes, declarations for "X" and "Y", the identifier "X" and "Y", and the constants 2 and 3. Note also, that it encodes lists of declarations and lists of statements by simply having each declarations/statements last child be the next declaration.

start: start ::= declarations statements
^ statements.env = declarations.env
^ start.type_ok ::= statements.type_ok
decl_stop: declarations ::= Îμ
^ declarations.env = nil
decl_x_int: declarations1 ::= declarations2
^ declarations1.env =
decl_y_int: declarations1 ::= declarations2
^ declarations1.env =
decl_x_bool: declarations1 ::= declarations2
^ declarations1.env =
decl_y_bool: declarations1 ::= declarations2
^ declarations1.env =
stmt_stop: statements ::= Îμ
^ statements.type_ok = true
stmt_if: statements1 ::= expr statements2 statements3 statements4
^ statements1.type_ok = (expr.type == BOOL)
and statements2.type_ok
and statements3.type_ok
and statements4.type_ok
^ expr.env = statements1.env
^ statements2.env = statements1.env
^ statements3.env = statements1.env
^ statements4.env = statements1.env
stmt_prepareint: statements1 ::= expr statements2
^ statements1.type_ok = (expr.type == INT) and statements2.type_ok
^ expr.env = statements1.env
^ statements2.env = statements1.env
<: expr1 ::= expr2 expr3
^ expr1.type = if expr2.type == INT and expr3.type == INT then BOOL else ERR
^ expr2.env = expr1.env
^ expr3.env = expr1.env
+: expr1 ::= expr2 expr3
^ expr1.type = if expr2.type == INT and expr3.type == INT then INT else ERR
^ expr2.env = expr1.env
^ expr3.env = expr1.env
*: epxr1 ::= expr2 expr3
^ expr1.type = if expr2.type == INT and expr3.type == INT then INT else ERR
^ expr2.env = expr1.env
^ expr3.env = expr1.env

2: expr ::= Îμ
^ expr.type = INT

3: expr ::= Îμ
^ expr.type = INT
id_x: expr ::= Îμ
^ expr.type = lookup(X, expr.env)
id_y: expr ::= Îμ
^ expr.type = lookup(Y, expr.env)
With the auxilary function lookup:
lookup(X, env) = if env = nil
then ERR
else let = env in
if Y = X then n else lookup(X, env2)
end

(a) Of the attributes, declarations.env, statements.env, statements.type_ok, expr.env, and expr.type, which are inherited? Which are synthesized?

(b) Is the grammar L-attributed?

(c) Consider the following tree:

start
|
+-decl_x_int
| |
| +-decl_y_bool
| |
| +-decl_stop
|
+-stmt_if
|
+-<
| |
| +-id_x
| |
| +-3
|
+-stmt_prepare
| |
| +-id_y
| |
| +-stmt_stop
|
+-stmt_stop
|
+-stmt_stop

Show how the tree might be type-checked. Annotate the nodes in the tree with numbers indicating the order in which you find outd them? Below, using the same numbering, show the attribute values computed at each step of the evaluation.

(d) Is there a type error in the program represented by this AST? If so, what is it?

2. Consider the TL13' type rules in the posted lecture notes.

(a) Derive a proof tree showing that the following program is well-typed according to those rules:

program begin while true do prepareInt 25 ; end ; end

That is, the judgement:

[] |- program begin while true do prepareInt 25 ; end ; end

(b) Derive a proof tree justifying the judgement that following statement sequence is well-typed under the environment [][x -> int][b -> bool]:

while b do prepareInt x end ;

That is, the judgement:

[][x -> int][b -> bool] |- while b do prepareInt x end ;

(c) Attempt to derive proof tree for the judgment [][x -> bool] |- x * 5 + 2 : int. What premise cannot be satisfied because it doesn't match any rule? Show your incomplete tree circling the unjustified leaf premise (at the top of the tree).

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91703

Have any Question?


Related Questions in Programming Language

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As