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

Write a program that creates a picture of a mountain

Write a program that creates a picture of a mountain panorama from a height profile entered by the user. The following screenshot shows what the output could look like: The picture shall consist of 5 text lines of length ...

Assignmentgoalsto learn about separate compilation classes

Assignment Goals To learn about separate compilation, classes, and vector manipulation. Your Assignment In this assignment the main has been written for you in the file phone_book_main.cpp. You will also notice that a cl ...

Assignment research projectwrite an overview of any two of

Assignment: Research Project Write an overview of *any two* of the below topics. Each overview should be between one half and one full page long. You should use a minimum of two sources for each overview; make sure to re ...

Program assignment multi-threaded programming in java

Program Assignment: Multi-threaded Programming in Java Using Locks Objectives: To practice programming cooperating, synchronized multiple threads of execution. Description: In this programming assignment you will simulat ...

Suppose a basic block is formed from the c assignment

Suppose a basic block is formed from the C assignment statements x = a + b + c + d + e + f; y = a + c + e; a) Give the three-address statements (only one addition per statement) for this block. b) Use the associative and ...

Programming project sorting to find anagramssee project 4

Programming Project Sorting to find anagrams See Project 4 on pg. 869 for the basic ideas of this project. We will find the longest anagrams in the words.txt provided in the Chapter 13 files on the author's website. 1. F ...

Construct a loop which will allow for the daily fan count

Construct a loop which will allow for the daily fan count to be entered for each game. The games number (1-4) should be part of the prompt displayed to the user. Within this loop, you will need other loop(s) to validate ...

Assignmenta catering company provides prepared meals for

Assignment A catering company provides prepared meals for events such as business meetings. The company has a number of standard meals, which it identifies with a unique integer ID number. At this stage each meal also ha ...

Assignmentreference this assignment is an object oriented

Assignment Reference: This assignment is an object oriented version of the In-class assignment. The functionality supported for a single vehicle in ICA 01 would be extended to multiple vehicles using a single class Car, ...

Write a gui application that prints out hello in either

Write a GUI application that prints out "Hello!" in either: English, French, or Spanish. When the user selects another language, the greeting shown in the greeting area should change. Your GUI should look like the interf ...

  • 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

WalMart Identification of theory and critical discussion

Drawing on the prescribed text and/or relevant academic literature, produce a paper which discusses the nature of group

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro