Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer Problem 3, the question references something from Problem 2 so included that - don't answer that question. Problem 2: Consider the following grammar

image text in transcribedimage text in transcribedPlease answer Problem 3, the question references something from Problem 2 so included that - don't answer that question.

Problem 2: Consider the following grammar (yes, it is ambiguous but that is unimportant). The subscripts are used to distinguish otherwise identical non-terminals for the purpose of the questions below. ; int double = + + - | * : + a legal name in the language a base 10 representation of an integer a base 10 representation of a floating point number Suppose our static semantic description has five attributes: type = { integer, double } typetable() = { integer, double, error } inittable() = { true, false, error } typebinding = (, { integer, double }) initialized = (, { true, false }) typetable maps each possible variable name to its declared type, and inittable maps each possible variable name to a boolean indicating whether the variable has been assigned a value. Initially, both typetable and inittable will map all possible variable names to error to indicate that the variables have not been declared in the program. typebinding maps a single variable name to its declared type, and initialized maps a single variable name to whether it has been assigned a value. For each subscripted non-terminal, provide a rule to calculate its type, table, inittable, typebindig, and ini- tialized attributes, if that non-terminal requires that attribute. Each attribute should either be inherited or synthesized, but not both. For example, here are two such rules: .type := integer .initialized := (, false) (Here I am using := to create a mapping so you can use = to mean only mathematical equality.) Problem 3: Suppose we want to enforce the following rules in the grammar from Problem 2: (a) The type of the expression must match the type of the variable in all assignment statements. (b) A variable must be declared before it can be used. (c) A variable must be assigned a value as its first use in the program. Where in the parse tree should these rules be checked (i.e. at which non-terminals), and write the precise tests that should be done at those non-terminals using the attibutes available. Problem 2: Consider the following grammar (yes, it is ambiguous but that is unimportant). The subscripts are used to distinguish otherwise identical non-terminals for the purpose of the questions below. ; int double = + + - | * : + a legal name in the language a base 10 representation of an integer a base 10 representation of a floating point number Suppose our static semantic description has five attributes: type = { integer, double } typetable() = { integer, double, error } inittable() = { true, false, error } typebinding = (, { integer, double }) initialized = (, { true, false }) typetable maps each possible variable name to its declared type, and inittable maps each possible variable name to a boolean indicating whether the variable has been assigned a value. Initially, both typetable and inittable will map all possible variable names to error to indicate that the variables have not been declared in the program. typebinding maps a single variable name to its declared type, and initialized maps a single variable name to whether it has been assigned a value. For each subscripted non-terminal, provide a rule to calculate its type, table, inittable, typebindig, and ini- tialized attributes, if that non-terminal requires that attribute. Each attribute should either be inherited or synthesized, but not both. For example, here are two such rules: .type := integer .initialized := (, false) (Here I am using := to create a mapping so you can use = to mean only mathematical equality.) Problem 3: Suppose we want to enforce the following rules in the grammar from Problem 2: (a) The type of the expression must match the type of the variable in all assignment statements. (b) A variable must be declared before it can be used. (c) A variable must be assigned a value as its first use in the program. Where in the parse tree should these rules be checked (i.e. at which non-terminals), and write the precise tests that should be done at those non-terminals using the attibutes available

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Generative Artificial Intelligence For Project Management With Aws

Authors: Timothy Krimmel

1st Edition

B0CQV9KWB8, 979-8872627197

More Books

Students also viewed these Databases questions