Question

Consider the following context free grammar. Write an attribute grammar that specifies the calculation rules, i.e....

Consider the following context free grammar. Write an attribute grammar that specifies the calculation rules, i.e. how the value of E or T is calculated. There is no need to perform type checking. We assume all types are matched correctly. Please clearly specify the type of attribute(s) you introduce, i.e. synthesized, inherited, or intrinsic. E ::= E + T | T T ::= T * F | F F ::= NUM NUM ::= 1 | 2 | 3 | 4 | 5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer : Given Context free grammar is E ::= E + T | T T ::= T * F | F F ::= NUM NUM ::= 1 | 2 | 3 | 4 | 5

                  Grammars with attributes stored at each node is called attribute grammar.

                   Productions                       Attribute Grammar

                   E ::= E1 + T                     E.val = E1 .val + T . val

   E ::= T                                  E.val = T . val

                   T ::= T * F                             T.val = T1 .val * F . val

                   T ::= F                                   T.val = F . val

                   F ::= NUM                             F.val = NUM.val

                   NUM ::= 1                             NUM.lexval = 1

                   NUM ::= 2                              NUM.lexval = 2

                   NUM ::= 3                              NUM.lexval = 3

                   NUM ::= 4                               NUM.lexval = 4

                   NUM ::= 5                              NUM.lexval = 5

                   Synthesized attributes are those computed from children. Inherited attributes computed from sibling or

                   parent.

                 Here all attributes 'val' are synthesized as its computed from child nodes attribute.

                 For example   in , E.val = E1 .val + T . val

                 To compute value of E , we need to compute value of E1 and value of T..

                 NUM.lexval is intrinsic attribute.

                Here there is no inherited attribute.

                  

Add a comment
Know the answer?
Add Answer to:
Consider the following context free grammar. Write an attribute grammar that specifies the calculation rules, i.e....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using the following grammar write an attributes grammar that can calculate the decimal value of an...

    Using the following grammar write an attributes grammar that can calculate the decimal value of an octal number. Grammar: number = list list = list octal | octal octal = ‘0’ | ‘1’ | ‘2’ | ‘3’ | ‘4’ | ‘5’ | ‘6’ | ‘7’ Notes: An octal number consists of octal digits, i.e. 0 to 7. The following example shows how to convert the octal 67 to its equivalent decimal. The symbol star represents multiplication. 67 = 6 *...

  • 1 - Semantics - Attributes Grammar (25 points) Using the following grammar write an attributes grammar...

    1 - Semantics - Attributes Grammar (25 points) Using the following grammar write an attributes grammar that can calculate the decimal value of an octal number. Grammar: number = list list = list octal octal octal = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7' Notes: An octal number consists of octal digits, i.e. O to 7. The following example shows how to convert the octal 67 to its equivalent decimal. The symbol star represents multiplication. 67 = 6*87 + 7* 8° = 6 * 8 +...

  • Consider the context-free grammar with the rules (E is start variable) E → E + T...

    Consider the context-free grammar with the rules (E is start variable) E → E + T | T T → T × F | F F → ( E ) | a Convert CFG to an equivalent PDA using the procedure given in Theorem 2.20.

  • Consider the following context-free grammar: E + E +T|T T + TxFF F + (E) |...

    Consider the following context-free grammar: E + E +T|T T + TxFF F + (E) | a How many production rules does this grammar have?

  • 2. Consider the following context free grammar with terminals (), +, id, num, and starting symbol...

    2. Consider the following context free grammar with terminals (), +, id, num, and starting symbol S. S (ST) F-id Fnum a. Compute the first and follow set of all non-terminals (use recursion or iteration, show all the steps) Show step-by-step (the parsing tree) how the following program is parsed: (num+num+id)) b.

  • 3 points) Question Three Consider the context-free grammar S >SS+1 SS 1a and the string aa...

    3 points) Question Three Consider the context-free grammar S >SS+1 SS 1a and the string aa Give a leftmost derivation for the string. 3 points) (4 poiots) (5 points) (3 points) sECTION IWOLAttcmpt.any 3.(or 2) questions from this.scction Suppose we have two tokens: (1) the keyword if, and (2) id-entifiers, which are strings of letters other than if. Show the DFA for these tokens. Give a nightmost derivation for the string. Give a parse tree for the string i) Is...

  • 1. (p. 2-3.) Which of the following is NOT a reason for studying concepts of programming...

    1. (p. 2-3.) Which of the following is NOT a reason for studying concepts of programming languages according to Sebesta? a. Increased capacity to express ideas. b. Improved background for choosing appropriate languages. c. Increased ability to design new languages. d. Increased ability to learn new languages. 2. (p. 5-6.) What programming language has dominated scientific computing over the past 50 years? a. FORTRAN b. ALGOL c. SNOBOL d. PL/I 3. (p. 6.) What programming language has dominated artificial intelligence...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

  • First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below...

    First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below Include each of the following in your answer (if applicable – explain in a paragraph) Research problem: what do you want to solve using Delphi? Sample: who will participate and why? (answer in 5 -10 sentences) Round one questionnaire: include 5 hypothetical questions you would like to ask Discuss: what are possible outcomes of the findings from your study? Hint: this is the conclusion....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT