Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an attribute grammar that has its BNF basis as the following grammar: -> =

ID: 3744581 • Letter: W

Question

Write an attribute grammar that has its BNF basis as the following grammar: -> = -> + | -> A | B | C Note that the tokens in the grammar are highlighted in bold. You need to extend the above grammar into an attribute grammar to address the below language rules: a. Data types cannot be mixed in expressions, and b. Assignment statements need to have the same types on both sides of the assignment operator. Note that you need write the complete attribute grammar including both syntax and semantics rules for the language. (Reference: Textbook example 3.6.)

please give an original answer

Explanation / Answer

S -> convert (<var>) = convert (<expr>) | E

convert(<expr>) -> convert (<expr>) + convert (<var>) | convert(<var>) | E

E -> "Error in conversion due to invalid type"

<var> -> A | B | C

So, here in the above given Production Rules:-

S -> Start Symbol, {expr, var, S, E} = Set of Non Terminals, {A, B, C, "Error in conversion due to invalid type"} = Set of Terminals

convert() = will try to convert the data types of expr, and var into equivalent types so that no mixed operations are done. In case data types are not equivalent upon conversion, it throws error E. Same applies to Assignment Statements, if equal types arent present it throws error E.

Please let me know in case of any clarifications required. Thanks!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote