1. [15] Consider the following grammar. Again all the nonterminals are all surrounded by angle brackets ((...)) and everything else is a terminal. a | (aseq) a (bseq) b | (cseq) c (aseq) (bseq) = (cseq) a (string) ::= (aseq) (bseq) (cseq) (hstring) := (num) H (string) Assume that (num) is defined using an attribute grammar that defines an integer and asso- ciates with (num) an attribute val representing its numerical value. (a) [10] Add semantic actions and appropriate attributes to the grammar to (a) compute the length of a string generated by (string), and (b) ensure that an (hstring) is valid if and only if the number preceding H is equal to the length of the string following H. (b) [5] For each attribute used in the previous question state its type (synthesized or inher- ited) and explain why this is so.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.5: Virtual Functions
Problem 5E
icon
Related questions
Question
1. [15] Consider the following grammar. Again all the nonterminals are all surrounded by
angle brackets ((...)) and everything else is a terminal.
a | (aseq) a
(bseq) b
| (cseq) c
(aseq)
(bseq)
=
(cseq)
a
(string) ::=
(aseq) (bseq) (cseq)
(hstring) :=
(num) H (string)
Assume that (num) is defined using an attribute grammar that defines an integer and asso-
ciates with (num) an attribute val representing its numerical value.
(a) [10] Add semantic actions and appropriate attributes to the grammar to (a) compute
the length of a string generated by (string), and (b) ensure that an (hstring) is valid if
and only if the number preceding H is equal to the length of the string following H.
(b) [5] For each attribute used in the previous question state its type (synthesized or inher-
ited) and explain why this is so.
Transcribed Image Text:1. [15] Consider the following grammar. Again all the nonterminals are all surrounded by angle brackets ((...)) and everything else is a terminal. a | (aseq) a (bseq) b | (cseq) c (aseq) (bseq) = (cseq) a (string) ::= (aseq) (bseq) (cseq) (hstring) := (num) H (string) Assume that (num) is defined using an attribute grammar that defines an integer and asso- ciates with (num) an attribute val representing its numerical value. (a) [10] Add semantic actions and appropriate attributes to the grammar to (a) compute the length of a string generated by (string), and (b) ensure that an (hstring) is valid if and only if the number preceding H is equal to the length of the string following H. (b) [5] For each attribute used in the previous question state its type (synthesized or inher- ited) and explain why this is so.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT