Fill This Form To Receive Instant Help
Homework answers / question archive / Consider the following grammar, which supports the syntax needed to return a value from a subroutine call
Consider the following grammar, which supports the syntax needed to return a value from a subroutine call.
Stmt→Assignment | FunCall | return id | FunDefAssignment→id := ExprFunCall→Name ( ArgList )FunDefType Name ( ParamList )Expr→Primary ExprTailExprTail →op expr | εPrimary →id | SubrCall | ( Expr ) Op →+ | - | * | / ArgList →Expr ArgsTail | εArgsTail →, ArgList | ε ParamList→Type id ParamTail | εParamTail→, ParamList | εName→idType→int | float | void
Briefly sketch out the salient design of an Attribute Grammar, which extends the above Context-Free grammar, that would be required to handle the static semantics associated with making a function call.
x = foo(a, b)
You should demonstrate you understand attributes, inherited attributes, and synthesized attributes.
Answer:
A Synthesized attribute is an attribute of the non-terminal on the left-hand side of a production. Synthesized attributes represent information that is being passed up the parse tree. The attribute can take value only from its children (Variables in the RHS of the production)
An attribute is said to be Inherited attribute if its parse tree node value is determined by the attribute value at parent and/or siblings node
Inherited attribute is used by only L attributed SDT.