Ask Question, Ask an Expert

+1-415-315-9853

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

Part a-1 what arguments can you make for the idea of a

Part A- 1. What arguments can you make for the idea of a single programming language for all programming domains? It would be ideal to have a single programming language for all 2. What arguments can you make against the ...

Cp1404cp5632 2016 sp22252 assignment 1 - shopping list

CP1404/CP5632 2016 SP2/22/52 Assignment 1 - Shopping List 1.0 Task: You are to plan and then code a console-based program in Python 3, as described in the following information and sample output. This assignment will hel ...

Integrative programmingassignment- managing a user account

Integrative Programming Assignment- Managing a User Account List Objective: To manage a user list that can be modified and saved to a text file. Inputs: • Input text file consisting of pairs of usernames and passwords, s ...

Pair programming phase 1talent agency user stories1 user

Pair Programming Phase 1 Talent Agency User Stories 1. User Story 1 As a head office administrator I want to be able to produce formatted output of all the information about our talent agencies so that I can easily incor ...

1 tic tac toein a tic tac toe game two players x and o take

1 TIC TAC TOE In a Tic Tac Toe game two players, X and O, take turns to mark the spaces in a 3X3 grid. The winner will be the player who first succeeds in placing three of his/her marks in a horizontal, vertical, or diag ...

Questioncomplete tutorial 10 case problem 2 - ridgewood

Question: Complete Tutorial 10 Case Problem 2 - Ridgewood Herald Tribune found on pages 734-736 of your textbook. Complete the entire website assignment and upload your files to your 000WebHost account. After uploading t ...

Assignmentyou will write a program that acts like a simple

Assignment You will write a program that acts like a simple calculator for binary numbers. You should read in a string of input that has the format: number operator number. Each of the numbers should be presented in two' ...

The briefyour small development team of ideally three

The Brief Your small development team of (ideally) three people has been asked to implement and test the Human Resource Information System desktop application. Your software product will be a database- backed desktop app ...

Object oriented system analysis and design1non-functional

Object Oriented System Analysis and Design 1. Non-Functional Requirements a) Analysis of NFRs Analyse the Case Study documents and determine the non-functional requirements (NFRs) or system quality attributes necessary t ...

1 loops the greatest and the least- write a program with a

1. Loops: The greatest and the least- Write a program with a loop that lets the user to enter a series of integers. The use should enter -99 to signal the end of the series. After all the numbers have been entered, the p ...

  • 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

A cola-dispensing machine is set to dispense 9 ounces of

A cola-dispensing machine is set to dispense 9 ounces of cola per cup, with a standard deviation of 1.0 ounce. The manuf

What is marketingbullwhat is marketing think back to your

What is Marketing? • "What is marketing"? Think back to your impressions before you started this class versus how you

Question -your client david smith runs a small it

QUESTION - Your client, David Smith runs a small IT consulting business specialising in computer software and techno

Inspection of a random sample of 22 aircraft showed that 15

Inspection of a random sample of 22 aircraft showed that 15 needed repairs to fix a wiring problem that might compromise

Effective hrmquestionhow can an effective hrm system help

Effective HRM Question How can an effective HRM system help facilitate the achievement of an organization's strate